IDEA+Java+SSM+Mysql+JSP实现Web宠物商城系统(上)

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: IDEA+Java+SSM+Mysql+JSP实现Web宠物商城系统

一、系统介绍


1.开发环境


开发工具:IDEA2018


JDK版本:jdk1.8


Mysql版本:8.0.13


2.技术选型


Java+Spring+SpringMVC+Mybatis+JSP+Mysql


3.系统功能


用户


1.注册


2.登录


3.浏览商品


4.购买商品


5.评论


管理员


1.登录


2.用户查看


3.一级分类管理


4.二级分类管理


5.商品管理


6.订单管理


7.留言管理


二、系统展示


1.用户-主页面


70aa46e7fe8f4acb9f4a1a6ab93dd887.jpg


2.用户-注册


3511d2b0134644c6ac20cfbe1fd16874.jpg


3.用户-登录


2e5edfedf67d4378be568c6551d31a44.jpg


4.用户-商品分类


295c3cf1e1ba46a29abd251d46f8a9d9.jpg


5.用户-查看商品


694a2201155345b4b883463845dbac41.jpg


6.用户-提交订单


aabc55f06e94496aa56bdb02125aae5c.jpg


7.用户-支付货款


7d61ab7ff45b49b2bbf483d31c33e8b3.jpg


8.用户-留言板


67edc13545054742bc72570ff594f396.jpg


9.管理员-登录


eea6916096444fb5880290e67803cd6c.jpg


10.管理员-用户查看


9eabc5e975f64029a980cbed624bba60.jpg


11.管理员-一级分类管理


1a368862cb7d42a7b8bb73498488ebac.jpg


12.管理员-二级分类管理


1bf73b5d48744396b7b7eedb84c542ae.jpg


13.管理员-商品管理


38c6dd801a85441792ff37b9893eb024.jpg


14.管理员-订单管理


6d59766dfbf849ef94c1020f3c85a471.jpg


15.管理员-留言管理


852a484df15e420495c4f082b2126ed4.jpg


三、部分代码


AdminController

package com.shop.controller;
import java.io.File;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import com.shop.Utils.PageBean;
import com.shop.Utils.UUIDUtiils;
import com.shop.po.Adminuser;
import com.shop.po.Category;
import com.shop.po.Categorysecond;
import com.shop.po.Message;
import com.shop.po.Orders;
import com.shop.po.Product;
import com.shop.po.User;
import com.shop.service.CategorySecondService;
import com.shop.service.CategoryService;
import com.shop.service.MessageService;
import com.shop.service.OrderService;
import com.shop.service.ProductService;
import com.shop.service.UserService;
@Controller
public class AdminController {
    @Autowired
    private UserService userService;
    @Autowired
    public CategoryService categoryService;
    @Autowired
    public CategorySecondService categorySecondService;
    @Autowired
    public ProductService productService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private MessageService messageService;
    @RequestMapping("/admin/admin_findAll")
    public String admin_findAll(Model model, HttpServletRequest request) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        List<User> userList = userService.admin_findAll();
        model.addAttribute("userList", userList);
        return "admin/user/list";
    }
    @RequestMapping("/admin/adminCategory_findAll")
    public String adminCategory_findAll(Model model, HttpServletRequest request)
            throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        List<Category> categoryList = categoryService.adminbFindCategory();
    /*for (Category category : categoryList) {
      System.out.println(category.getCname());
    }*/
        model.addAttribute("categoryList", categoryList);
        return "admin/category/list";
    }
    @RequestMapping("/admin/adminCategory_add")
    public String adminCategory_add(Model model, HttpServletRequest request) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
//    List<Category> categoryList = categoryService.adminbFindCategory();
//    model.addAttribute("categoryList", categoryList);
        return "admin/category/add";
    }
    @RequestMapping("/admin/adminCategory_save")
    public String adminCategory_save(@RequestParam String cname, HttpServletRequest request)
            throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        Category addCategory = new Category();
        addCategory.setCname(cname);
        categoryService.addCategory(addCategory);
        return "redirect:/admin/adminCategory_findAll.action";
    }
    @RequestMapping("/admin/adminCategory_edit")
    public String adminCategory_delete(@RequestParam int cid, Model model, HttpServletRequest request)
            throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        Category existCategory = categoryService.findCategory(cid);
        model.addAttribute("existCategory", existCategory);
        return "admin/category/edit";
    }
    @RequestMapping("/admin/adminCategory_update")
    public String adminCategory_update(@RequestParam int cid,
                                       @RequestParam String cname, HttpServletRequest request) {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        Category category = new Category();
        category.setCid(cid);
        category.setCname(cname);
        categoryService.adminCategory_update(category);
        return "redirect:/admin/adminCategory_findAll.action";
    }
    @RequestMapping("/admin/adminCategory_delete")
    public String adminCategory_delete(@RequestParam int cid, HttpServletRequest request) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        categorySecondService.adminCategorySecond_deleteByCid(cid);
        categoryService.deleteCategoryByCid(cid);
        return "redirect:/admin/adminCategory_findAll.action";
    }
    // admin 的二级分类的管理
    @RequestMapping("/admin/adminCategorySecond_findAllByPage")
    public String adminCategorySecond_findAllByPage(@RequestParam int page, Model model, HttpServletRequest request) {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        PageBean<Categorysecond> csPageBean = categorySecondService
                .adminCategorySecond_findAllByPage(page);
    /*List<Categorysecond> list = csPageBean.getList();
    for (Categorysecond categorysecond : list) {
      System.out.println(categorysecond.getCsname());
    }*/
        model.addAttribute("csPageBean", csPageBean);
        return "admin/categorysecond/list";
    }
    @RequestMapping("admin/adminCategorySecond_addPage")
    public String adminCategorySecond_addPage(Model model, HttpServletRequest request) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        List<Category> categoryList = categoryService.adminbFindCategory();
        model.addAttribute("categoryList", categoryList);
        return "admin/categorysecond/add";
    }
    @RequestMapping("admin/adminCategorySecond_save")
    public String adminCategorySecond_save(@RequestParam String csname, @RequestParam int cid, HttpServletRequest request) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        Categorysecond categorysecond = new Categorysecond();
        categorysecond.setCsname(csname);
        categorysecond.setCid(cid);
        categorySecondService.adminCategorySecond_save(categorysecond);
        return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
    }
    @RequestMapping("admin/adminCategorySecond_edit")
    public String adminCategorySecond_edit(@RequestParam int csid, Model model, HttpServletRequest request) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        Categorysecond findByCsid = categorySecondService.findByCsid(csid);
        model.addAttribute("findByCsid", findByCsid);
        return "admin/categorysecond/edit";
    }
    @RequestMapping("admin/adminCategorySecond_update")
    public String adminCategorySecond_update(@RequestParam String csname, @RequestParam int csid, HttpServletRequest request) {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        Categorysecond categorysecond = new Categorysecond();
        categorysecond.setCsname(csname);
        categorysecond.setCsid(csid);
        categorySecondService.adminCategorySecond_update(categorysecond);
        return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
    }
    @RequestMapping("admin/adminCategorySecond_delete")
    public String adminCategorySecond_delete(@RequestParam int csid, HttpServletRequest request) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        categorySecondService.adminCategorySecond_delete(csid);
        return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
    }
    //admin的商品管理
    @RequestMapping("/admin/adminProduct_findAllByPage")
    public String adminProduct_findAllByPage(@RequestParam int page, Model model, HttpServletRequest request)
            throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        PageBean<Product> allProPageBean = productService.findAllProduct(page);
        model.addAttribute("allProPageBean", allProPageBean);
        return "admin/product/list";
    }
    @RequestMapping("/admin/adminProduct_addPage")
    public String adminProduct_addPage(Model model, HttpServletRequest request) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        //查询出所有的二级分类
        List<Categorysecond> cslist = categorySecondService.findAll();
    /*for (Categorysecond categorysecond : cslist) {
      System.out.println(categorysecond.getCsname());
    }*/
        model.addAttribute("cslist", cslist);
        return "admin/product/add";
    }
    @RequestMapping("/admin/adminProduct_save")
    public String adminProduct_save(Product product, HttpServletRequest request, MultipartFile file) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        product.setPdate(new Date());
//    上传图片
        if (file != null) {
            String path = request.getServletContext().getRealPath(
                    "/products");
            String uploadFileName = file.getOriginalFilename();
            String fileName = UUIDUtiils.getUUID() + uploadFileName;
            File diskFile = new File(path + "//" + fileName);
            file.transferTo(diskFile);
            product.setImage("products/" + fileName);
        }
        System.out.println(product.getImage());
        productService.adminProduct_save(product);
        return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
    }
    @RequestMapping("admin/adminProduct_deletecs")
    public String adminProduct_deletecs(@RequestParam int pid, HttpServletRequest request) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        productService.adminProduct_deletecs(pid);
        return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
    }
    /**
     * 编辑商品
     *
     * @param pid
     * @param model
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("admin/adminProduct_edit")
    public String adminProduct_edit(@RequestParam int pid, Model model, HttpServletRequest request) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        Product product = productService.finbProductByPid(pid);
        model.addAttribute("findByPid", product);
        //查询出所有的二级分类
        List<Categorysecond> cslist = categorySecondService.findAll();
        model.addAttribute("cslist", cslist);
        return "admin/product/edit";
    }
    @RequestMapping("/admin/adminProduct_update")
    public String adminProduct_update(Product product, HttpServletRequest request, MultipartFile file) throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        product.setPdate(new Date());
//    上传图片
        if (file != null) {
            String path = request.getServletContext().getRealPath(
                    "/products");
            String uploadFileName = file.getOriginalFilename();
            String fileName = UUIDUtiils.getUUID() + uploadFileName;
            File diskFile = new File(path + "//" + fileName);
            file.transferTo(diskFile);
            product.setImage("products/" + fileName);
        }
        productService.adminProduct_update(product);
        return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
    }
    /**
     * 订单管理模块
     **/
    @RequestMapping("/admin/adminOrder_findAllByPage")
    public String adminOrder_findAllByPage(@RequestParam int page, Model model, HttpServletRequest request)
            throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        PageBean<Orders> allProPageBean = orderService.findAllOrderByStateAndPage(page);
        model.addAttribute("pageBean", allProPageBean);
        return "admin/order/list";
    }
    //adminOrder_findByState
    @RequestMapping("/admin/adminOrder_findByState")
    public String adminOrder_findByState(@RequestParam int page, @RequestParam int state, Model model, HttpServletRequest request)
            throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        PageBean<Orders> allProPageBean = orderService.findAllOrderByStateAndPage(state, page);
        model.addAttribute("pageBean", allProPageBean);
        return "admin/order/list";
    }
    //订单详情
    //adminOrder_findOrderItem
    @RequestMapping("/admin/adminOrder_findOrderItem")
    public String adminOrder_findOrderItem(@RequestParam int oid, Model model, HttpServletRequest request)
            throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        Orders orderItems = orderService.findOrderByOid(oid);
        model.addAttribute("orderItems", orderItems);
        return "admin/order/list";
    }
    //更新订单状态
    @RequestMapping("/admin/adminOrder_updateState")
    public String adminOrder_updateState(@RequestParam int oid, @RequestParam int status, Model model, HttpServletRequest request)
            throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        orderService.updateOrderStatus(oid, status);
        return "redirect:/admin/adminOrder_findAllByPage.action?page=1";
    }
    //后台留言管理
    @RequestMapping("/admin/adminMessage_findAllByPage")
    public String adminMessage_findAllByPage(@RequestParam int page, Model model, HttpServletRequest request)
            throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        PageBean<Message> pageBean = messageService.findAllMessageByPage(page);
        model.addAttribute("pageBean", pageBean);
        return "admin/message/list";
    }
    @RequestMapping("/admin/adminMessage_delete")
    public String adminOrder_updateState(@RequestParam int messageid, Model model, HttpServletRequest request)
            throws Exception {
        Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
        if (adminuserLogin == null) {
            request.getSession().setAttribute("message", "对不起您还没有登录");
            return "admin/index";
        }
        messageService.deleteMessage(messageid);
        return "redirect:/admin/adminMessage_findAllByPage.action?page=1";
    }
}


相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1月前
|
关系型数据库 MySQL Java
【IDEA】java后台操作mysql数据库驱动常见错误解决方案
【IDEA】java后台操作mysql数据库驱动常见错误解决方案
56 0
|
4天前
|
Java
轻松上手Java字节码编辑:IDEA插件VisualClassBytes全方位解析
本插件VisualClassBytes可修改class字节码,包括class信息、字段信息、内部类,常量池和方法等。
31 6
|
2月前
|
前端开发 JavaScript Java
基于Java+Springboot+Vue开发的服装商城管理系统
基于Java+Springboot+Vue开发的服装商城管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Java编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Java的服装商城管理系统项目,大学生可以在实践中学习和提升自己的能力,为以后的职业发展打下坚实基础。
142 2
基于Java+Springboot+Vue开发的服装商城管理系统
|
7天前
|
前端开发 Oracle 关系型数据库
关于使用SSM+JSP开发时setter、getter隐式调用问题的小结
本文主要分享了在使用SSM+JSP进行网站开发时,因忽视setter、getter的隐式调用问题而导致的常见bug及其解决方法。详细介绍了setter和getter的隐式调用时机,并给出了具体示例,帮助开发者避免类似问题。
33 11
|
1月前
|
存储 缓存 Java
java基础:IO流 理论与代码示例(详解、idea设置统一utf-8编码问题)
这篇文章详细介绍了Java中的IO流,包括字符与字节的概念、编码格式、File类的使用、IO流的分类和原理,以及通过代码示例展示了各种流的应用,如节点流、处理流、缓存流、转换流、对象流和随机访问文件流。同时,还探讨了IDEA中设置项目编码格式的方法,以及如何处理序列化和反序列化问题。
67 1
java基础:IO流 理论与代码示例(详解、idea设置统一utf-8编码问题)
|
19天前
|
搜索推荐 Java 数据库连接
Java|在 IDEA 里自动生成 MyBatis 模板代码
基于 MyBatis 开发的项目,新增数据库表以后,总是需要编写对应的 Entity、Mapper 和 Service 等等 Class 的代码,这些都是重复的工作,我们可以想一些办法来自动生成这些代码。
28 6
|
2月前
|
设计模式 Java 关系型数据库
【Java笔记+踩坑汇总】Java基础+JavaWeb+SSM+SpringBoot+SpringCloud+瑞吉外卖/谷粒商城/学成在线+设计模式+面试题汇总+性能调优/架构设计+源码解析
本文是“Java学习路线”专栏的导航文章,目标是为Java初学者和初中高级工程师提供一套完整的Java学习路线。
387 37
|
2月前
|
前端开发 JavaScript Java
基于Java+Springboot+Vue开发的蛋糕商城管理系统
基于Java+Springboot+Vue开发的蛋糕商城管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Java编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Java的蛋糕商城管理系统项目,大学生可以在实践中学习和提升自己的能力,为以后的职业发展打下坚实基础。
136 3
基于Java+Springboot+Vue开发的蛋糕商城管理系统
|
2月前
|
Java 关系型数据库 MySQL
毕设项目&课程设计&毕设项目:springboot+jsp实现的房屋租租赁系统(含教程&源码&数据库数据)
本文介绍了一款基于Spring Boot和JSP技术的房屋租赁系统,旨在通过自动化和信息化手段提升房屋管理效率,优化租户体验。系统采用JDK 1.8、Maven 3.6、MySQL 8.0、JSP、Layui和Spring Boot 2.0等技术栈,实现了高效的房源管理和便捷的租户服务。通过该系统,房东可以轻松管理房源,租户可以快速找到合适的住所,双方都能享受数字化带来的便利。未来,系统将持续优化升级,提供更多完善的服务。
毕设项目&课程设计&毕设项目:springboot+jsp实现的房屋租租赁系统(含教程&源码&数据库数据)
|
2月前
|
前端开发 JavaScript Java
基于Java+Springboot+Vue开发的母婴商城管理系统
基于Java+Springboot+Vue开发的母婴商城管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Java编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Java的网上母婴商城管理系统项目,大学生可以在实践中学习和提升自己的能力,为以后的职业发展打下坚实基础。
51 7
基于Java+Springboot+Vue开发的母婴商城管理系统