基于javaweb+mysql的ssm超市便利店管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Layui Ajax)

基于javaweb+mysql的ssm超市便利店管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Layui Ajax)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

技术框架

JavaBean MVC JSP SSM(Spring SpringMVC MyBatis) MySQL CSS JavaScript Layui Ajax

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

登录、注册、退出、用户模块、公告模块、商品模块、订单模块、供应商模块的增删改查管理

eclipse/MyEclipse运行:

idea运行:

        request.getRequestDispatcher("login.jsp").forward(request, response);
    }

    @RequestMapping("authLogout")
    public void logout(HttpServletResponse response, HttpServletRequest request) throws IOException {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("loginUser");
        if (user != null) {
            session.removeAttribute("loginUser");
        }
        response.sendRedirect("login.jsp");
    }

    @RequestMapping("authValidationCode")
    public void validationCode(HttpServletResponse response, HttpServletRequest request) throws IOException {
        String codeChars = "0123456789";// 图形验证码的字符集合,系统将随机从这个字符串中选择一些字符作为验证码
        //  获得验证码集合的长度
        int charsLength = codeChars.length();
        //  下面三条记录是关闭客户端浏览器的缓冲区
        //  这三条语句都可以关闭浏览器的缓冲区,但是由于浏览器的版本不同,对这三条语句的支持也不同
        //  因此,为了保险起见,建议同时使用这三条语句来关闭浏览器的缓冲区
        response.setHeader("ragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        //  设置图形验证码的长和宽(图形的大小)
        int width = 90, height = 20;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();//  获得用于输出文字的Graphics对象
        Random random = new Random();
        g.setColor(getRandomColor(180, 250));// 随机设置要填充的颜色
        g.fillRect(0, 0, width, height);//  填充图形背景
        //  设置初始字体
        g.setFont(new Font("Times New Roman", Font.ITALIC, height));
        g.setColor(getRandomColor(120, 180));// 随机设置字体颜色
        //  用于保存最后随机生成的验证码
        StringBuilder validationCode = new StringBuilder();
        //  验证码的随机字体
        String[] fontNames = {"Times New Roman", "Book antiqua", "Arial"};
        for (int i = 0; i < 4; i++) {
            //  随机设置当前验证码的字符的字体
            g.setFont(new Font(fontNames[random.nextInt(3)], Font.ITALIC, height));
            //  随机获得当前验证码的字符
            char codeChar = codeChars.charAt(random.nextInt(charsLength));
            validationCode.append(codeChar);
            //  随机设置当前验证码字符的颜色
            g.setColor(getRandomColor(10, 100));
            //  在图形上输出验证码字符,x和y都是随机生成的
            g.drawString(String.valueOf(codeChar), 16 * i + random.nextInt(7), height - random.nextInt(6));
        }
        HttpSession session = request.getSession();
        session.setMaxInactiveInterval(5 * 60);
        //  将验证码保存在session对象中,key为validation_code
        session.setAttribute("validationCode", validationCode.toString());
        g.dispose();//  关闭Graphics对象
    /**
     * 编辑商品
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("goodEdit")
    public void edit(Good vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        goodService.update(vo);
        this.redirectList(request, response);
    }

    /**
     * 获取商品的详细信息(详情页面与编辑页面要显示该商品的详情)并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping({"goodGet", "goodEditPre"})
    public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");//取出主键id
        Good vo = goodService.get(id);
        request.getSession().setAttribute("vo", vo);
        String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
        response.sendRedirect("good_" + to + ".jsp");
    }

    /**
     * 根据条件查询商品的列表并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("goodList")
    public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
        this.redirectList(request, response);
    }

    /**
     * 跳转到列表页面
     *
     * @param request
     * @param response
     */
    private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {

@Controller
public class AuthController extends HttpServlet {
    @Autowired
    private UserService userService;

    @RequestMapping("authLogin")
    public void login(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        String validationCode = request.getParameter("validationCode");
        if (validationCode != null && !validationCode.equals(request.getSession().getAttribute("validationCode"))) {//验证码不通过
            request.getSession().setAttribute("alert_msg", "错误:验证码不正确!");
            request.getRequestDispatcher("login.jsp").forward(request, response);
            return;
        }

        Map<String, Object> params = new HashMap();
        
        
        List<User> list = (List<User>) userService.list(params).get("list");
        for (User user : list) {
            if (user.getUsername().equals(username) && user.getPassword().equals(password)) {//找到这个管理员了
                request.getSession().setAttribute("loginUser", user);
				request.getSession().setMaxInactiveInterval(Integer.MAX_VALUE);
                request.getRequestDispatcher("user_list.jsp").forward(request, response);
                return;
            }
        }
        request.getSession().setAttribute("alert_msg", "错误:用户名或密码错误!");
        request.getRequestDispatcher("login.jsp").forward(request, response);
    }

    @RequestMapping("authRegister")
    public void register(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println("username=" + username);
        System.out.println("password=" + password);

        Map<String, Object> params = new HashMap();
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("supplierAdd")
    public void add(Supplier vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        //调用Service层的增加(insert)方法
        supplierService.insert(vo);
        this.redirectList(request, response);
    }

    /**
     * 删除供应商
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("supplierDelete")
    public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");
        supplierService.delete(Arrays.asList(id));
        this.redirectList(request, response);
    }

    /**
     * 编辑供应商
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("supplierEdit")
    public void edit(Supplier vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        supplierService.update(vo);
        this.redirectList(request, response);
    }

    /**
     * 获取供应商的详细信息(详情页面与编辑页面要显示该供应商的详情)并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping({"supplierGet", "supplierEditPre"})
    public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");//取出主键id
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        String validationCode = request.getParameter("validationCode");
        if (validationCode != null && !validationCode.equals(request.getSession().getAttribute("validationCode"))) {//验证码不通过
            request.getSession().setAttribute("alert_msg", "错误:验证码不正确!");
            request.getRequestDispatcher("login.jsp").forward(request, response);
            return;
        }

        Map<String, Object> params = new HashMap();
        
        
        List<User> list = (List<User>) userService.list(params).get("list");
        for (User user : list) {
            if (user.getUsername().equals(username) && user.getPassword().equals(password)) {//找到这个管理员了
                request.getSession().setAttribute("loginUser", user);
				request.getSession().setMaxInactiveInterval(Integer.MAX_VALUE);
                request.getRequestDispatcher("user_list.jsp").forward(request, response);
                return;
            }
        }
        request.getSession().setAttribute("alert_msg", "错误:用户名或密码错误!");
        request.getRequestDispatcher("login.jsp").forward(request, response);
    }

    @RequestMapping("authRegister")
    public void register(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println("username=" + username);
        System.out.println("password=" + password);

        Map<String, Object> params = new HashMap();
        
        
        params.put("startIndex", 0);
        params.put("pageSize", Long.MAX_VALUE);
        List<User> list = (List<User>) userService.list(params).get("list");
        for (User user : list) {
            if (user.getUsername().equals(username) /*&& user.getPassword().equals(password)*/) {//说明该用户名已存在,必须换个用户名才能注册
                request.getSession().setAttribute("alert_msg", "错误:用户名已存在!");
                request.getRequestDispatcher("register.jsp").forward(request, response);
                return;
            }
     * 增加商品
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("goodAdd")
    public void add(Good vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        //调用Service层的增加(insert)方法
        goodService.insert(vo);
        this.redirectList(request, response);
    }

    /**
     * 删除商品
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("goodDelete")
    public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");
        goodService.delete(Arrays.asList(id));
        this.redirectList(request, response);
    }

    /**
     * 编辑商品
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("goodEdit")
    public void edit(Good vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        goodService.update(vo);
        this.redirectList(request, response);
    }

    /**
     * 获取商品的详细信息(详情页面与编辑页面要显示该商品的详情)并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("orderList")
    public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
        this.redirectList(request, response);
    }

    /**
     * 跳转到列表页面
     *
     * @param request
     * @param response
     */
    private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //查询列和关键字
        String searchColumn = request.getParameter("searchColumn");
        String keyword = request.getParameter("keyword");
        Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
        params.put("searchColumn", searchColumn);//要查询的列
        params.put("keyword", keyword);//查询的关键字
        response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(orderService.list(params).get("list")));
    }
}
package com.demo.controller;

@Controller
@RequestMapping
public class GoodController {

    @Autowired
    private GoodService goodService;

    /**
     * 增加商品
     *
    }

    /**
     * 删除用户
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("userDelete")
    public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");
        userService.delete(Arrays.asList(id));
        this.redirectList(request, response);
    }

    /**
     * 编辑用户
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("userEdit")
    public void edit(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        userService.update(vo);
        this.redirectList(request, response);
    }

    /**
     * 获取用户的详细信息(详情页面与编辑页面要显示该用户的详情)并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping({"userGet", "userEditPre"})
    public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");//取出主键id
        User vo = userService.get(id);
        request.getSession().setAttribute("vo", vo);
        String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
        response.sendRedirect("user_" + to + ".jsp");
    }

    /**
     * 根据条件查询用户的列表并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("userList")
    }

    /**
     * 根据条件查询订单的列表并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("orderList")
    public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
        this.redirectList(request, response);
    }

    /**
     * 跳转到列表页面
     *
     * @param request
     * @param response
     */
    private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //查询列和关键字
        String searchColumn = request.getParameter("searchColumn");
        String keyword = request.getParameter("keyword");
        Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
        params.put("searchColumn", searchColumn);//要查询的列
        params.put("keyword", keyword);//查询的关键字
        response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(orderService.list(params).get("list")));
    }
}
package com.demo.controller;

@Controller
@RequestMapping
        params.put("searchColumn", searchColumn);//要查询的列
        params.put("keyword", keyword);//查询的关键字
        response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(supplierService.list(params).get("list")));
    }
}
package com.demo.controller;

@Controller
@RequestMapping
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    /**
     * 增加公告
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("noticeAdd")
    public void add(Notice vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        //调用Service层的增加(insert)方法
        //  验证码的随机字体
        String[] fontNames = {"Times New Roman", "Book antiqua", "Arial"};
        for (int i = 0; i < 4; i++) {
            //  随机设置当前验证码的字符的字体
            g.setFont(new Font(fontNames[random.nextInt(3)], Font.ITALIC, height));
            //  随机获得当前验证码的字符
            char codeChar = codeChars.charAt(random.nextInt(charsLength));
            validationCode.append(codeChar);
            //  随机设置当前验证码字符的颜色
            g.setColor(getRandomColor(10, 100));
            //  在图形上输出验证码字符,x和y都是随机生成的
            g.drawString(String.valueOf(codeChar), 16 * i + random.nextInt(7), height - random.nextInt(6));
        }
        HttpSession session = request.getSession();
        session.setMaxInactiveInterval(5 * 60);
        //  将验证码保存在session对象中,key为validation_code
        session.setAttribute("validationCode", validationCode.toString());
        g.dispose();//  关闭Graphics对象
        OutputStream os = response.getOutputStream();
        ImageIO.write(image, "JPEG", os);// 以JPEG格式向客户端发送图形验证码
    }

    @RequestMapping("authResetPassword")
    public void resetPassword(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
        String msg;
        User loginUser = (User) request.getSession().getAttribute("loginUser");
        String oldPassword = request.getParameter("oldPassword");
        if (!loginUser.getPassword().equals(oldPassword)) {
            msg = "原密码错误!";
        } else {
            String newPassword = request.getParameter("newPassword");
            loginUser.setPassword(newPassword);
            this.userService.update(loginUser);
            msg = "修改成功!";
        }
        request.getSession().setAttribute("alert_msg", msg);
        request.getRequestDispatcher("reset_password.jsp").forward(request, response);
    }

    // 返回一个随机颜色(Color对象)
    private Color getRandomColor(int minColor, int maxColor) {
        this.redirectList(request, response);
    }

    /**
     * 删除商品
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("goodDelete")
    public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");
        goodService.delete(Arrays.asList(id));
        this.redirectList(request, response);
    }

    /**
     * 编辑商品
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("goodEdit")
    public void edit(Good vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        goodService.update(vo);
        this.redirectList(request, response);
    }

    /**
     * 获取商品的详细信息(详情页面与编辑页面要显示该商品的详情)并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping({"goodGet", "goodEditPre"})
    public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");//取出主键id
        Good vo = goodService.get(id);
        request.getSession().setAttribute("vo", vo);
        String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
        response.sendRedirect("good_" + to + ".jsp");
    }
    }

    /**
     * 获取公告的详细信息(详情页面与编辑页面要显示该公告的详情)并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping({"noticeGet", "noticeEditPre"})
    public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");//取出主键id
        Notice vo = noticeService.get(id);
        request.getSession().setAttribute("vo", vo);
        String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
        response.sendRedirect("notice_" + to + ".jsp");
    }

    /**
     * 根据条件查询公告的列表并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("noticeList")
    public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
        this.redirectList(request, response);
    }

    /**
     * 跳转到列表页面
     *
     * @param request
     * @param response
     */
    private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //查询列和关键字
        String searchColumn = request.getParameter("searchColumn");
        String keyword = request.getParameter("keyword");
        Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
        params.put("searchColumn", searchColumn);//要查询的列
        params.put("keyword", keyword);//查询的关键字
        response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(noticeService.list(params).get("list")));
    }
}
package com.demo.controller;


@Controller
@RequestMapping
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 增加订单
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("orderAdd")
    public void add(Order vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        //调用Service层的增加(insert)方法
        orderService.insert(vo);
        this.redirectList(request, response);
    }

    /**
     * 删除订单
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("orderDelete")
    public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");
        orderService.delete(Arrays.asList(id));
        this.redirectList(request, response);
    }

    /**
     * 编辑订单
     *
        //查询列和关键字
        String searchColumn = request.getParameter("searchColumn");
        String keyword = request.getParameter("keyword");
        Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
        params.put("searchColumn", searchColumn);//要查询的列
        params.put("keyword", keyword);//查询的关键字
        response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(orderService.list(params).get("list")));
    }
}
package com.demo.controller;

@Controller
@RequestMapping
public class GoodController {

    @Autowired
    private GoodService goodService;

    /**
     * 增加商品
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("goodAdd")
    public void add(Good vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        response.sendRedirect("supplier_" + to + ".jsp");
    }

    /**
     * 根据条件查询供应商的列表并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("supplierList")
    public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
        this.redirectList(request, response);
    }

    /**
     * 跳转到列表页面
     *
     * @param request
     * @param response
     */
    private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //查询列和关键字
        String searchColumn = request.getParameter("searchColumn");
        String keyword = request.getParameter("keyword");
        Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
        params.put("searchColumn", searchColumn);//要查询的列
        params.put("keyword", keyword);//查询的关键字
        response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(supplierService.list(params).get("list")));
    }
}
package com.demo.controller;

@Controller
@RequestMapping
public class NoticeController {

    @Autowired
    @RequestMapping({"supplierGet", "supplierEditPre"})
    public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");//取出主键id
        Supplier vo = supplierService.get(id);
        request.getSession().setAttribute("vo", vo);
        String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
        response.sendRedirect("supplier_" + to + ".jsp");
    }

    /**
     * 根据条件查询供应商的列表并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("supplierList")
    public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
        this.redirectList(request, response);
    }

    /**
     * 跳转到列表页面
     *
     * @param request
     * @param response
     */
    private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //查询列和关键字
        String searchColumn = request.getParameter("searchColumn");
        String keyword = request.getParameter("keyword");
        Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
        params.put("searchColumn", searchColumn);//要查询的列
        params.put("keyword", keyword);//查询的关键字
        response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(supplierService.list(params).get("list")));
    }
}
package com.demo.controller;

        goodService.update(vo);
        this.redirectList(request, response);
    }

    /**
     * 获取商品的详细信息(详情页面与编辑页面要显示该商品的详情)并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping({"goodGet", "goodEditPre"})
    public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");//取出主键id
        Good vo = goodService.get(id);
        request.getSession().setAttribute("vo", vo);
        String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
        response.sendRedirect("good_" + to + ".jsp");
    }

    /**
     * 根据条件查询商品的列表并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("goodList")
    public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
        this.redirectList(request, response);
    }

    /**
     * 跳转到列表页面
     *
     * @param request
     * @param response
     */
    private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //查询列和关键字
        String searchColumn = request.getParameter("searchColumn");
        String keyword = request.getParameter("keyword");
        Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
        params.put("searchColumn", searchColumn);//要查询的列
        params.put("keyword", keyword);//查询的关键字
        response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(goodService.list(params).get("list")));
    }
}
package com.demo.controller;


@Controller
@RequestMapping
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 增加用户
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("userAdd")
    public void add(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        //调用Service层的增加(insert)方法
        userService.insert(vo);
        this.redirectList(request, response);
    }

    /**
     * 删除用户
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("userDelete")
    public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");
        userService.delete(Arrays.asList(id));
        this.redirectList(request, response);
    }

    /**
        Serializable id = request.getParameter("id");
        supplierService.delete(Arrays.asList(id));
        this.redirectList(request, response);
    }

    /**
     * 编辑供应商
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("supplierEdit")
    public void edit(Supplier vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        supplierService.update(vo);
        this.redirectList(request, response);
    }

    /**
     * 获取供应商的详细信息(详情页面与编辑页面要显示该供应商的详情)并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping({"supplierGet", "supplierEditPre"})
    public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");//取出主键id
        Supplier vo = supplierService.get(id);
        request.getSession().setAttribute("vo", vo);
        String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
        response.sendRedirect("supplier_" + to + ".jsp");
    }

    /**
     * 根据条件查询供应商的列表并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("supplierList")
    public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
        this.redirectList(request, response);
    }

    public void add(Good vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        //调用Service层的增加(insert)方法
        goodService.insert(vo);
        this.redirectList(request, response);
    }

    /**
     * 删除商品
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("goodDelete")
    public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");
        goodService.delete(Arrays.asList(id));
        this.redirectList(request, response);
    }

    /**
     * 编辑商品
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("goodEdit")
    public void edit(Good vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        goodService.update(vo);
        this.redirectList(request, response);
    }

    /**
     * 获取商品的详细信息(详情页面与编辑页面要显示该商品的详情)并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping({"goodGet", "goodEditPre"})
    public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");//取出主键id
        Good vo = goodService.get(id);
        request.getSession().setAttribute("vo", vo);
        String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
            String newPassword = request.getParameter("newPassword");
            loginUser.setPassword(newPassword);
            this.userService.update(loginUser);
            msg = "修改成功!";
        }
        request.getSession().setAttribute("alert_msg", msg);
        request.getRequestDispatcher("reset_password.jsp").forward(request, response);
    }

    // 返回一个随机颜色(Color对象)
    private Color getRandomColor(int minColor, int maxColor) {
        Random random = new Random();
        // 保存minColor最大不会超过255
        if (minColor > 255)
            minColor = 255;
        //  保存minColor最大不会超过255
        if (maxColor > 255)
            maxColor = 255;
        //  获得红色的随机颜色值
        int red = minColor + random.nextInt(maxColor - minColor);
        //  获得绿色的随机颜色值
        int green = minColor + random.nextInt(maxColor - minColor);
        //  获得蓝色的随机颜色值
        int blue = minColor + random.nextInt(maxColor - minColor);
        return new Color(red, green, blue);
    }
}
package com.demo.controller;

@Controller
@RequestMapping
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    /**
     * 增加供应商
        
        
        List<User> list = (List<User>) userService.list(params).get("list");
        for (User user : list) {
            if (user.getUsername().equals(username) && user.getPassword().equals(password)) {//找到这个管理员了
                request.getSession().setAttribute("loginUser", user);
				request.getSession().setMaxInactiveInterval(Integer.MAX_VALUE);
                request.getRequestDispatcher("user_list.jsp").forward(request, response);
                return;
            }
        }
        request.getSession().setAttribute("alert_msg", "错误:用户名或密码错误!");
        request.getRequestDispatcher("login.jsp").forward(request, response);
    }

    @RequestMapping("authRegister")
    public void register(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println("username=" + username);
        System.out.println("password=" + password);

        Map<String, Object> params = new HashMap();
        
        
        params.put("startIndex", 0);
        params.put("pageSize", Long.MAX_VALUE);
        List<User> list = (List<User>) userService.list(params).get("list");
        for (User user : list) {
            if (user.getUsername().equals(username) /*&& user.getPassword().equals(password)*/) {//说明该用户名已存在,必须换个用户名才能注册
                request.getSession().setAttribute("alert_msg", "错误:用户名已存在!");
                request.getRequestDispatcher("register.jsp").forward(request, response);
                return;
            }
        }
        User vo = new User();
        vo.setUsername(username);
        vo.setPassword(password);
        //vo.setUserType("普通用户");//需要设置一个默认值
        userService.insert(vo);
        request.getSession().setAttribute("alert_msg", "注册成功!用户名:[" + username + "]");
        request.getRequestDispatcher("login.jsp").forward(request, response);
    }

    @RequestMapping("authLogout")
    public void logout(HttpServletResponse response, HttpServletRequest request) throws IOException {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("loginUser");
        if (user != null) {
            session.removeAttribute("loginUser");
        }
        response.sendRedirect("login.jsp");
    }

    }
}
package com.demo.controller;

@Controller
@RequestMapping
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 增加用户
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("userAdd")
    public void add(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        //调用Service层的增加(insert)方法
        userService.insert(vo);
        this.redirectList(request, response);
    }

    /**
     * 删除用户
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("userDelete")
    public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {

@Controller
@RequestMapping
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 增加用户
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("userAdd")
    public void add(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
        //调用Service层的增加(insert)方法
        userService.insert(vo);
        this.redirectList(request, response);
    }

    /**
     * 删除用户
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("userDelete")
    public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = request.getParameter("id");
        userService.delete(Arrays.asList(id));
        this.redirectList(request, response);
    }

    /**
     * 编辑用户

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、项目简介本课程演示的是一套基于JavaWeb实现的超市管理系统,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的Java学习者。课程包含:1. 项目源码、项目文档、数据库脚本、软件工具等所有资料2. 带你从零开始部署运行本套系统3. 该项目附带的源码资料可作为毕设使用4. 提供技术答疑二、技术实现后台框架:ServletJSP、JDBC UI界面:BootStrap、jQuery数据库:MySQL 三、系统功能该系统共包含两种角色:员工和管理员。系统的主要功能模块如下:1. 系统管理 系统登陆、系统退出、修改密码 2. 员工信息管理 员工用户管理、增加员工用户、员工用户查询 3. 商品信息管理 商品信息管理、增加商品信息、商品信息查询 4. 货架信息管理 货架信息管理、增加货架信息、货架信息查询 5. 商品类型管理 商品类型管理、增加商品类型 6. 进货信息管理 进货信息管理、增加进货信息、进货信息查询 7. 销售信息管理 销售信息管理、增加销售信息、销售信息查询 8. 库存信息管理 库存信息盘点、库存信息查询、缺货信息提醒 9. 盈利信息管理 盈利信息查询、盈利信息统计、盈利信息分析该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。 四、项目截图1)系统登陆界面 2)管理员界面 3)员工界面  更多Java毕设项目请关注【毕设系列课程】https://edu.csdn.net/lecturer/2104  点击 我的百科 ,通过百度百科更多了解我 ^_^ 

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值