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

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 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月前
|
Java 应用服务中间件 开发工具
如何使用IDEA创建JSP页面
如何使用IDEA创建JSP页面
141 0
|
2月前
|
设计模式 Java 关系型数据库
【Java笔记+踩坑汇总】Java基础+JavaWeb+SSM+SpringBoot+SpringCloud+瑞吉外卖/谷粒商城/学成在线+设计模式+面试题汇总+性能调优/架构设计+源码解析
本文是“Java学习路线”专栏的导航文章,目标是为Java初学者和初中高级工程师提供一套完整的Java学习路线。
432 37
|
1月前
|
Java 应用服务中间件 Maven
idea+maven+tomcat+spring 创建一个jsp项目
这篇文章介绍了如何在IntelliJ IDEA中使用Maven和Tomcat创建一个JSP项目,包括配置Maven依赖、设置Tomcat服务器、编写JSP页面、创建控制器和配置文件,以及项目的运行结果。
188 0
idea+maven+tomcat+spring 创建一个jsp项目
|
2月前
|
前端开发 Java 数据库连接
【Java笔记+踩坑】SSM整合
统一结果封装、统一异常处理、整合图书案例、拦截器
【Java笔记+踩坑】SSM整合
|
3月前
|
Java
`<jsp:getProperty>`动作和`<jsp:setProperty>`动作的使用在一个静态页面填写图书的基本信息,页面信息提交给其他页面,并且在其页面显示。要去将表单元素的值赋值给Java
该博客文章讲解了JSP中`<jsp:getProperty>`和`<jsp:setProperty>`动作的使用方法,包括它们的语法格式和如何在页面中使用这些动作来获取和设置JavaBean对象的属性值,并通过图书信息的填写和展示示例进行了演示。
`<jsp:getProperty>`动作和`<jsp:setProperty>`动作的使用在一个静态页面填写图书的基本信息,页面信息提交给其他页面,并且在其页面显示。要去将表单元素的值赋值给Java
|
3月前
|
存储 缓存 前端开发
Servlet与JSP在Java Web应用中的性能调优策略
Servlet与JSP在Java Web应用中的性能调优策略
34 1
|
3月前
|
XML JSON Java
使用IDEA+Maven搭建整合一个Struts2+Spring4+Hibernate4项目,混合使用传统Xml与@注解,返回JSP视图或JSON数据,快来给你的SSH老项目翻新一下吧
本文介绍了如何使用IntelliJ IDEA和Maven搭建一个整合了Struts2、Spring4、Hibernate4的J2EE项目,并配置了项目目录结构、web.xml、welcome.jsp以及多个JSP页面,用于刷新和学习传统的SSH框架。
93 0
使用IDEA+Maven搭建整合一个Struts2+Spring4+Hibernate4项目,混合使用传统Xml与@注解,返回JSP视图或JSON数据,快来给你的SSH老项目翻新一下吧
|
3月前
|
存储 Java 关系型数据库
基于Servlet和JSP的Java Web应用开发指南
基于Servlet和JSP的Java Web应用开发指南
56 0
|
3月前
|
Java
jsp和java的结合使用显示学生信息
通过JavaBean封装学生信息,并利用JSP展示。`Student`类定义了学生属性与操作方法。JSP页面通过脚本创建学生对象、填充数据至列表,并遍历输出。实现了学生基本信息的动态展示。
|
5月前
|
存储 Java 关系型数据库
基于Servlet和JSP的Java Web应用开发指南
【6月更文挑战第23天】构建Java Web应用,Servlet与JSP携手打造在线图书管理系统,涵盖需求分析、设计、编码到测试。通过实例展示了Servlet如何处理用户登录(如`LoginServlet`),JSP负责页面展示(如`login.jsp`和`bookList.jsp`)。应用基于MySQL数据库,包含用户和图书表。登录失败显示错误信息,成功后展示图书列表。部署到Tomcat服务器测试功能。此基础教程为深入Java Web开发奠定了基础。
116 10

热门文章

最新文章

下一篇
无影云桌面