第五阶段淘宝项目java+html+mysql(一)

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 第五阶段淘宝项目java+html+mysql

文章目录


代码展示

Dao层实现

UserDaoImpl

IUserDao

ShoppingDaoImpl

Dao层接口

Service层接口

IShoppingService

Service层实现

UserServiceImpl

ShoppingServiceImpl

实体层

User

Shoping

Controller层

ChangeServlet

ClearServlet

CommodityServlet

DeletServlet

InsertUserServlet

LogoutServlet

QueryServlet

RegisterServlet

UpdatenumServlet

前端html

change.jsp

commod.jsp

delete.jsp

enter.jsp

index.jsp

login.jsp

logout.jsp

panduan.jsp

panduan1.jsp

panduan2.jsp

panduan3.jsp

panduan4.jsp

shopping.jsp

css


代码展示


Dao层实现


UserDaoImpl


package org.lyl.taobao.dao.impl;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.dao.IUserDao;
import java.sql.*;
public class UserDaoImpl implements IUserDao {
    @Override
    public boolean insertUser(User user) throws SQLException {
        boolean x = true;
        Connection conn = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
        String sql = "insert into user values(null,?,?,?)";
        String sql1 = "select * from user";
        java.sql.Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(sql1);
        while (rs.next()) {
            String name = rs.getString("uername");
            if (name.equals(user.getUserName())) {
                x = false;
            }
        }
        if (x==true) {
            PreparedStatement pst = null;
            pst = conn.prepareStatement(sql);
            pst.setString(1, user.getUserName());
            pst.setString(2, user.getUserPassword());
            pst.setString(3, user.getPhone());
            int len = pst.executeUpdate();
            if (len>0){
                return true;
            }
        }
        return false;
    }
    @Override
    public boolean change(User user) throws ClassNotFoundException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob", "root", "asd.123");
            String sql = "select * from user";
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()){
                String name = rs.getString("uername");
                String phone = rs.getString("phone");
                if (name.equals(user.getUserName())&&phone.equals(user.getPhone())){
                    String sql1 = "UPDATE user SET PASSWORD=? WHERE uername=?";
                    PreparedStatement ps = conn.prepareStatement(sql1);
                    ps.setString(1,user.getUserPassword());
                    ps.setString(2,user.getUserName());
                    ps.execute();
                    return true;
                }
            }
        } catch (Exception e ) {
            e.printStackTrace();
            return false;
        }
        return false;
    }
    public static int uid;
    @Override
    public boolean register(User user) {
        try {
            Shoping shoping = new Shoping();
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
            String sql = "select * from user";
            java.sql.Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()){
                String paw = rs.getString("password");
                String name = rs.getString("uername");
                int id = rs.getInt("id");
                if (paw.equals(user.getUserPassword())&&name.equals(user.getUserName())){
                   uid = id;
                    return true;
                }
            }
            rs.close();
            st.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    @Override
    public boolean delete(User user) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
            String sql = "delete from user where uername=?";
            String sql1 = "select * from user";
            String sql2 = "delete from shopping where uid=?";
            java.sql.Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql1);
            PreparedStatement pr = conn.prepareStatement(sql);
            PreparedStatement pr1 = conn.prepareStatement(sql2);
            while (rs.next()){
                String name = rs.getString("uername");
                String password = rs.getString("password");
                if (name.equals(user.getUserName())&&password.equals(user.getUserPassword())) {
                    pr.setString(1,name);
                    pr1.setInt(1,uid);
                    pr.execute();
                    pr1.execute();
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return false;
    }
}

IUserDao


package org.lyl.taobao.dao;
import org.lyl.taobao.api.entity.User;
import java.sql.SQLException;
public interface IUserDao {
    boolean insertUser(User user) throws SQLException;
    boolean change(User user) throws ClassNotFoundException;
    boolean register(User user);
    boolean delete(User user);
}

ShoppingDaoImpl


package org.lyl.taobao.dao.impl;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.dao.IShoppingDao;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class ShoppingDaoImpl implements IShoppingDao {
    @Override
    public boolean commodity(Shoping shoping) {
        boolean z = false;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
            String sql = "insert into shopping values(null,?,?,?,?,?)";
            String sql1 = "select * from shopping";
            String sql2 = "update shopping set num = ? where name = ?";
            PreparedStatement pst = conn.prepareStatement(sql);
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql1);
            while (rs.next()) {
                String name = rs.getString("name");
                int uid = rs.getInt("uid");
                int num = rs.getInt("num");
                if (name.equals(shoping.getName())&&uid==UserDaoImpl.uid){
                    num ++;
                    PreparedStatement ps = conn.prepareStatement(sql2);
                    ps.setInt(1,num);
                    ps.setString(2,shoping.getName());
                    ps.execute();
                    z = true;
                    return true;
                }
            }
            if (z!=true){
                pst.setString(1,shoping.getName());
                pst.setString(2,shoping.getInformation());
                pst.setInt(3,shoping.getPrice());
                pst.setInt(4,shoping.getNum());
                pst.setInt(5,UserDaoImpl.uid);
            }
            int len = pst.executeUpdate();
            if (len>0){
                return true;
            }
            pst.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return false;
    }
    public static int x = 0;
    @Override
    public List<Shoping> query() {
//        ArrayList<String> list = new ArrayList<>();
        List<Shoping> list = new ArrayList<>();
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
            String sql = "select * from shopping";
            java.sql.Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()){
                int uid = rs.getInt("uid");
                if (uid==UserDaoImpl.uid){
                    int id = rs.getInt("id");
                    String name = rs.getString("name");
                    String information = rs.getString("information");
                    int price = rs.getInt("price");
                    int num = rs.getInt("num");
//                    String info = "商品名:" + name+"  |  " + "商品信息:" + information +"  |  "+ "价格:" + price +"  |  "+"数量:"+num;
//                    list.add(info);
                    Shoping shoping = new Shoping(id,name,information,price,num);
                    list.add(shoping);
                    x += price*num;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
//    @Override
//    public List queryid() {
//        ArrayList<Integer> list = new ArrayList<>();
//        try {
//            Class.forName("com.mysql.cj.jdbc.Driver");
//            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
//            String sql = "select * from shopping";
//            java.sql.Statement st = conn.createStatement();
//            ResultSet rs = st.executeQuery(sql);
//            while (rs.next()){
//                int uid = rs.getInt("uid");
//                if (uid==UserDaoImpl.uid){
//                    int id = rs.getInt("id");
//                    list.add(id);
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return list;
//    }
    @Override
    public boolean delet(Shoping shoping) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
            String sql = "delete from shopping where id=?";
            String sql1 = "select * from shopping";
            java.sql.Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql1);
            PreparedStatement pr = conn.prepareStatement(sql);
            while (rs.next()){
                int id = rs.getInt("id");
                int uid = rs.getInt("uid");
                if (shoping.getId()==id&&uid==UserDaoImpl.uid) {
                    pr.setInt(1,id);
                    pr.execute();
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return false;
    }
    @Override
    public boolean clear(Shoping shoping) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
            String sql = "delete from shopping where uid =?";
            String sql1 = "select * from shopping";
            PreparedStatement pr = conn.prepareStatement(sql);
            java.sql.Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql1);
            while (rs.next()){
                int uid = rs.getInt("uid");
                if (UserDaoImpl.uid==uid) {
                    pr.setInt(1,uid);
                    pr.execute();
                    return true;
                }
            }
            pr.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
    @Override
    public boolean update(Shoping shoping) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
            String sql1 = "select * from shopping";
            String sql2 = "update shopping set num = ? where id = ?";
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql1);
            while (rs.next()){
                int id = rs.getInt("id");
                int uid = rs.getInt("uid");
                int num = rs.getInt("num");
                if (id==shoping.getId()&&uid==UserDaoImpl.uid){
                    num--;
                    if (num==0){
                        return false;
                    }else {
                        PreparedStatement ps = conn.prepareStatement(sql2);
                        ps.setInt(1, num);
                        ps.setInt(2, id);
                        ps.execute();
                    }
                }
            }
            rs.close();
            st.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
}

Dao层接口


package org.lyl.taobao.dao;
import org.lyl.taobao.api.entity.Shoping;
import java.util.List;
public interface IShoppingDao {
    boolean commodity(Shoping shoping);
    List<Shoping> query();
//    List queryid();
    boolean delet(Shoping shoping);
    boolean clear(Shoping shoping);
    boolean update(Shoping shoping);
}

Service层接口


package org.lyl.taobao.api;
import org.lyl.taobao.api.entity.User;
import java.sql.SQLException;
public interface IUserService {
    boolean insertUser(User user) throws SQLException;
    boolean change(User user) throws ClassNotFoundException;
    boolean register(User user);
    boolean delete (User user);
}

IShoppingService


package org.lyl.taobao.api;
import org.lyl.taobao.api.entity.Shoping;
import java.util.List;
public interface IShoppingService {
    boolean commodity(Shoping shoping);
    List<Shoping> query();
    boolean delet(Shoping shoping);
    boolean clear(Shoping shoping);
    boolean update(Shoping shoping);
}


Service层实现


UserServiceImpl


package org.lyl.taobao.service;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.dao.IUserDao;
import org.lyl.taobao.dao.impl.UserDaoImpl;
import java.sql.SQLException;
public class UserServiceImpl implements IUserService {
    @Override
    public boolean insertUser(User user) throws SQLException {
        IUserDao iUserDao = new UserDaoImpl();
        return iUserDao.insertUser(user);
    }
    @Override
    public boolean change(User user) throws ClassNotFoundException {
        IUserDao iUserDao = new UserDaoImpl();
        return iUserDao.change(user);
    }
    @Override
    public boolean register(User user) {
        IUserDao iUserDao = new UserDaoImpl();
        return iUserDao.register(user);
    }
    @Override
    public boolean delete(User user) {
        IUserDao iUserDao = new UserDaoImpl();
        return iUserDao.delete(user);
    }
}

ShoppingServiceImpl


package org.lyl.taobao.service;
import org.lyl.taobao.api.IShoppingService;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.dao.IShoppingDao;
import org.lyl.taobao.dao.impl.ShoppingDaoImpl;
import java.util.List;
public class ShoppingServiceImpl implements IShoppingService {
    @Override
    public boolean commodity(Shoping shoping) {
        IShoppingDao iShoppingDao = new ShoppingDaoImpl();
       return iShoppingDao.commodity(shoping);
    }
    @Override
    public List<Shoping> query() {
        IShoppingDao iShoppingDao = new ShoppingDaoImpl();
        return iShoppingDao.query();
    }
    @Override
    public boolean delet(Shoping shoping) {
        IShoppingDao iShoppingDao = new ShoppingDaoImpl();
        return iShoppingDao.delet(shoping);
    }
    @Override
    public boolean clear(Shoping shoping) {
        IShoppingDao iShoppingDao = new ShoppingDaoImpl();
        return iShoppingDao.clear(shoping);
    }
    @Override
    public boolean update(Shoping shoping) {
        IShoppingDao iShoppingDao = new ShoppingDaoImpl();
        return iShoppingDao.update(shoping);
    }
}


实体层


User


package org.lyl.taobao.api.entity;
public class User {
    private String userName;
    private String userPassword;
    private String phone;
    /**
     * 用户注册和修改密码
     * @param userName
     * @param userPassword
     * @param phone
     */
    public User(String userName, String userPassword, String phone) {
        this.userName = userName;
        this.userPassword = userPassword;
        this.phone = phone;
    }
    /**
     * 用户登录
     * @param userName
     * @param userPassword
     */
    public User(String userName, String userPassword) {
        this.userName = userName;
        this.userPassword = userPassword;
    }
    public String getUserName() {
        return userName;
    }
    public String getPhone() {
        return phone;
    }
    public String getUserPassword() {
        return userPassword;
    }
    @Override
    public String toString() {
        return "User{" +
                "userName='" + userName + '\'' +
                ", userPassword='" + userPassword + '\'' +
                ", phone=" + phone +
                '}';
    }
}

Shoping


package org.lyl.taobao.api.entity;
public class Shoping {
    private  int id;
    private String name;
    private String information;
    private int price;
    private int num;
    private int uid;
    public Shoping() {
    }
    public Shoping(String name, String information, int price, int num) {
        this.name = name;
        this.information = information;
        this.price = price;
        this.num = num;
    }
    public Shoping(String name, String information, int price) {
        this.name = name;
        this.information = information;
        this.price = price;
    }
    public Shoping(int id) {
        this.id = id;
    }
    public Shoping(int id, String name, String information, int price, int num) {
        this.id = id;
        this.name = name;
        this.information = information;
        this.price = price;
        this.num = num;
    }
    public int getId() {
        return id;
    }
    public String getName() {
        return name;
    }
    public String getInformation() {
        return information;
    }
    public int getPrice() {
        return price;
    }
    public int getNum() {
        return num;
    }
    public int getUid() {
        return uid;
    }
    public void setUid(int uid) {
        this.uid = uid;
    }
    @Override
    public String toString() {
        return "Shooping{" +
                "name='" + name + '\'' +
                ", information='" + information + '\'' +
                ", price=" + price +
                ", num=" + num +
                '}';
    }
}

Controller层


ChangeServlet


package org.lyl.taobao.controller;
import lombok.SneakyThrows;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.service.UserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/change")
public class ChangeServlet extends HttpServlet {
    static boolean x ;
    @SneakyThrows
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");
        String name = req.getParameter("uname");
        String paw = req.getParameter("upaw");
        String num = req.getParameter("phone");
         if (name==""||paw==""||num==""){
             req.setAttribute("msg","输入的值不能为空!!!");
             req.getRequestDispatcher("change.jsp").forward(req,resp);
         }else {
             User user1 = new User(name,paw,num);
             IUserService iUserService = new UserServiceImpl();
             x = iUserService.change(user1);
             resp.sendRedirect("panduan1.jsp");
         }
    }
    public static boolean x() {
        return x;
    }
}

ClearServlet


package org.lyl.taobao.controller;
import org.lyl.taobao.api.IShoppingService;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.service.ShoppingServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/clear")
public class ClearServlet extends HttpServlet {
    public static boolean x;
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");
        Shoping shoping = new Shoping();
        IShoppingService iShoppingService = new ShoppingServiceImpl();
         x = iShoppingService.clear(shoping);
        if (x){
            resp.sendRedirect("shopping.jsp");
        }
    }
}

CommodityServlet


package org.lyl.taobao.controller;
import org.lyl.taobao.api.IShoppingService;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.service.ShoppingServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/com")
public class CommodityServlet extends HttpServlet {
    static boolean x;
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;utf-8");
        String name = req.getParameter("names");
        String information = req.getParameter("informations");
        int price = Integer.parseInt(req.getParameter("prices"));
        int num = Integer.parseInt(req.getParameter("num"));
        Shoping shoping1 = new Shoping(name,information,price,num);
        IShoppingService iShoppingService = new ShoppingServiceImpl();
         x = iShoppingService.commodity(shoping1);
         resp.sendRedirect("panduan3.jsp");
    }
    public static boolean x(){
        return x;
    }
}

DeletServlet


package org.lyl.taobao.controller;
import org.lyl.taobao.api.IShoppingService;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.service.ShoppingServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/del")
public class DeletServlet extends HttpServlet {
    static boolean x;
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        Shoping shoping = new Shoping(id);
        IShoppingService iShoppingService = new ShoppingServiceImpl();
         x =iShoppingService.delet(shoping);
         resp.sendRedirect("panduan2.jsp");
    }
    public static boolean x(){
        return x;
    }
}

InsertUserServlet


package org.lyl.taobao.controller;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.service.UserServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/insertUser")
public class InsertUserServlet extends HttpServlet {
    static boolean x;
    @lombok.SneakyThrows
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");
        String name = req.getParameter("names");
        String paw = req.getParameter("paw");
        String num = req.getParameter("num");
        if (name==""||paw==""||num==""){
            req.setAttribute("msg","输入的值不能为空!!!");
            req.getRequestDispatcher("login.jsp").forward(req,resp);
        }else {
            User user = new User(name,paw,num);
            IUserService iUserService = new UserServiceImpl();
            x = iUserService.insertUser(user);
            resp.sendRedirect("panduan4.jsp");
        }
    }
    public static boolean x() {
        return x;
    }
}

LogoutServlet


package org.lyl.taobao.controller;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.service.UserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/lout")
public class LogoutServlet extends HttpServlet {
    public static boolean x;
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;utf-8");
        String password = req.getParameter("password");
        User user = new User(RegisterServlet.name1,password);
        IUserService iUserService = new UserServiceImpl();
         x = iUserService.delete(user);
        if (x){
            resp.sendRedirect("index.jsp");
        }else {
            req.setAttribute("msg","密码错误,注销失败!!!");
            req.getRequestDispatcher("logout.jsp").forward(req,resp);
        }
    }
}

QueryServlet


package org.lyl.taobao.controller;
import org.lyl.taobao.api.IShoppingService;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.service.ShoppingServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@WebServlet("/que")
public class QueryServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;utf-8");
        HttpSession session = req.getSession();
        IShoppingService iShoppingService = new ShoppingServiceImpl();
        List<Shoping> shopings = iShoppingService.query();
        session.setAttribute("shop",shopings);
        resp.sendRedirect("shopping.jsp");
    }
//    public static List list(){
//        Shoping shoping = new Shoping();
//        IShoppingService iShoppingService = new ShoppingServiceImpl();
//        return iShoppingService.query(shoping);
//    }
}


相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
8天前
|
Java Maven
java项目中jar启动执行日志报错:no main manifest attribute, in /www/wwwroot/snow-server/z-server.jar-jar打包的大小明显小于正常大小如何解决
在Java项目中,启动jar包时遇到“no main manifest attribute”错误,且打包大小明显偏小。常见原因包括:1) Maven配置中跳过主程序打包;2) 缺少Manifest文件或Main-Class属性。解决方案如下:
java项目中jar启动执行日志报错:no main manifest attribute, in /www/wwwroot/snow-server/z-server.jar-jar打包的大小明显小于正常大小如何解决
|
5天前
|
存储 Java BI
java怎么统计每个项目下的每个类别的数据
通过本文,我们详细介绍了如何在Java中统计每个项目下的每个类别的数据,包括数据模型设计、数据存储和统计方法。通过定义 `Category`和 `Project`类,并使用 `ProjectManager`类进行管理,可以轻松实现项目和类别的数据统计。希望本文能够帮助您理解和实现类似的统计需求。
40 17
|
27天前
|
NoSQL Java 关系型数据库
Liunx部署java项目Tomcat、Redis、Mysql教程
本文详细介绍了如何在 Linux 服务器上安装和配置 Tomcat、MySQL 和 Redis,并部署 Java 项目。通过这些步骤,您可以搭建一个高效稳定的 Java 应用运行环境。希望本文能为您在实际操作中提供有价值的参考。
119 26
|
27天前
|
算法 Java API
如何使用Java开发获得淘宝商品描述API接口?
本文详细介绍如何使用Java开发调用淘宝商品描述API接口,涵盖从注册淘宝开放平台账号、阅读平台规则、创建应用并申请接口权限,到安装开发工具、配置开发环境、获取访问令牌,以及具体的Java代码实现和注意事项。通过遵循这些步骤,开发者可以高效地获取商品详情、描述及图片等信息,为项目和业务增添价值。
59 10
|
30天前
|
JavaScript 安全 Java
java版药品不良反应智能监测系统源码,采用SpringBoot、Vue、MySQL技术开发
基于B/S架构,采用Java、SpringBoot、Vue、MySQL等技术自主研发的ADR智能监测系统,适用于三甲医院,支持二次开发。该系统能自动监测全院患者药物不良反应,通过移动端和PC端实时反馈,提升用药安全。系统涵盖规则管理、监测报告、系统管理三大模块,确保精准、高效地处理ADR事件。
|
2月前
|
Java
Java项目中高精度数值计算:为何BigDecimal优于Double
在Java项目开发中,涉及金额计算、面积计算等高精度数值操作时,应选择 `BigDecimal` 而非 `Double`。`BigDecimal` 提供任意精度的小数运算、多种舍入模式和良好的可读性,确保计算结果的准确性和可靠性。例如,在金额计算中,`BigDecimal` 可以精确到小数点后两位,而 `Double` 可能因精度问题导致结果不准确。
|
14天前
|
存储 Oracle 关系型数据库
数据库传奇:MySQL创世之父的两千金My、Maria
《数据库传奇:MySQL创世之父的两千金My、Maria》介绍了MySQL的发展历程及其分支MariaDB。MySQL由Michael Widenius等人于1994年创建,现归Oracle所有,广泛应用于阿里巴巴、腾讯等企业。2009年,Widenius因担心Oracle收购影响MySQL的开源性,创建了MariaDB,提供额外功能和改进。维基百科、Google等已逐步替换为MariaDB,以确保更好的性能和社区支持。掌握MariaDB作为备用方案,对未来发展至关重要。
39 3
|
14天前
|
安全 关系型数据库 MySQL
MySQL崩溃保险箱:探秘Redo/Undo日志确保数据库安全无忧!
《MySQL崩溃保险箱:探秘Redo/Undo日志确保数据库安全无忧!》介绍了MySQL中的三种关键日志:二进制日志(Binary Log)、重做日志(Redo Log)和撤销日志(Undo Log)。这些日志确保了数据库的ACID特性,即原子性、一致性、隔离性和持久性。Redo Log记录数据页的物理修改,保证事务持久性;Undo Log记录事务的逆操作,支持回滚和多版本并发控制(MVCC)。文章还详细对比了InnoDB和MyISAM存储引擎在事务支持、锁定机制、并发性等方面的差异,强调了InnoDB在高并发和事务处理中的优势。通过这些机制,MySQL能够在事务执行、崩溃和恢复过程中保持
42 3
|
14天前
|
SQL 关系型数据库 MySQL
数据库灾难应对:MySQL误删除数据的救赎之道,技巧get起来!之binlog
《数据库灾难应对:MySQL误删除数据的救赎之道,技巧get起来!之binlog》介绍了如何利用MySQL的二进制日志(Binlog)恢复误删除的数据。主要内容包括: 1. **启用二进制日志**:在`my.cnf`中配置`log-bin`并重启MySQL服务。 2. **查看二进制日志文件**:使用`SHOW VARIABLES LIKE &#39;log_%&#39;;`和`SHOW MASTER STATUS;`命令获取当前日志文件及位置。 3. **创建数据备份**:确保在恢复前已有备份,以防意外。 4. **导出二进制日志为SQL语句**:使用`mysqlbinlog`
54 2
|
27天前
|
关系型数据库 MySQL 数据库
Python处理数据库:MySQL与SQLite详解 | python小知识
本文详细介绍了如何使用Python操作MySQL和SQLite数据库,包括安装必要的库、连接数据库、执行增删改查等基本操作,适合初学者快速上手。
184 15