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

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 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
相关文章
|
2月前
|
关系型数据库 MySQL Java
【MySQL+java+jpa】MySQL数据返回项目的感悟
【MySQL+java+jpa】MySQL数据返回项目的感悟
48 1
|
2月前
|
Java 应用服务中间件 开发工具
如何使用IDEA创建JSP页面
如何使用IDEA创建JSP页面
214 0
|
2月前
|
关系型数据库 MySQL Java
【IDEA】java后台操作mysql数据库驱动常见错误解决方案
【IDEA】java后台操作mysql数据库驱动常见错误解决方案
97 0
|
11天前
|
NoSQL Java 关系型数据库
Liunx部署java项目Tomcat、Redis、Mysql教程
本文详细介绍了如何在 Linux 服务器上安装和配置 Tomcat、MySQL 和 Redis,并部署 Java 项目。通过这些步骤,您可以搭建一个高效稳定的 Java 应用运行环境。希望本文能为您在实际操作中提供有价值的参考。
72 26
|
14天前
|
JavaScript 安全 Java
java版药品不良反应智能监测系统源码,采用SpringBoot、Vue、MySQL技术开发
基于B/S架构,采用Java、SpringBoot、Vue、MySQL等技术自主研发的ADR智能监测系统,适用于三甲医院,支持二次开发。该系统能自动监测全院患者药物不良反应,通过移动端和PC端实时反馈,提升用药安全。系统涵盖规则管理、监测报告、系统管理三大模块,确保精准、高效地处理ADR事件。
|
25天前
|
关系型数据库 MySQL Java
MySQL索引优化与Java应用实践
【11月更文挑战第25天】在大数据量和高并发的业务场景下,MySQL数据库的索引优化是提升查询性能的关键。本文将深入探讨MySQL索引的多种类型、优化策略及其在Java应用中的实践,通过历史背景、业务场景、底层原理的介绍,并结合Java示例代码,帮助Java架构师更好地理解并应用这些技术。
25 2
|
1月前
|
监控 前端开发 Java
【技术开发】接口管理平台要用什么技术栈?推荐:Java+Vue3+Docker+MySQL
该文档介绍了基于Java后端和Vue3前端构建的管理系统的技术栈及功能模块,涵盖管理后台的访问、登录、首页概览、API接口管理、接口权限设置、接口监控、计费管理、账号管理、应用管理、数据库配置、站点配置及管理员个人设置等内容,并提供了访问地址及操作指南。
|
2月前
|
SQL Java 关系型数据库
java连接mysql查询数据(基础版,无框架)
【10月更文挑战第12天】该示例展示了如何使用Java通过JDBC连接MySQL数据库并查询数据。首先在项目中引入`mysql-connector-java`依赖,然后通过`JdbcUtil`类中的`main`方法实现数据库连接、执行SQL查询及结果处理,最后关闭相关资源。
141 6
|
2月前
|
XML JSON API
ServiceStack:不仅仅是一个高性能Web API和微服务框架,更是一站式解决方案——深入解析其多协议支持及简便开发流程,带您体验前所未有的.NET开发效率革命
【10月更文挑战第9天】ServiceStack 是一个高性能的 Web API 和微服务框架,支持 JSON、XML、CSV 等多种数据格式。它简化了 .NET 应用的开发流程,提供了直观的 RESTful 服务构建方式。ServiceStack 支持高并发请求和复杂业务逻辑,安装简单,通过 NuGet 包管理器即可快速集成。示例代码展示了如何创建一个返回当前日期的简单服务,包括定义请求和响应 DTO、实现服务逻辑、配置路由和宿主。ServiceStack 还支持 WebSocket、SignalR 等实时通信协议,具备自动验证、自动过滤器等丰富功能,适合快速搭建高性能、可扩展的服务端应用。
158 3
|
1月前
|
设计模式 前端开发 数据库
Python Web开发:Django框架下的全栈开发实战
【10月更文挑战第27天】本文介绍了Django框架在Python Web开发中的应用,涵盖了Django与Flask等框架的比较、项目结构、模型、视图、模板和URL配置等内容,并展示了实际代码示例,帮助读者快速掌握Django全栈开发的核心技术。
171 45
下一篇
DataWorks