SpringBoot水果商城后台管理系统(文末附源码)

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,高可用系列 2核4GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: SpringBoot水果商城后台管理系统(文末附源码)

一、项目功能简介

(1)《SpringBoot水果商城后台管理系统》该项目采用技术:

《SpringBoot水果商城后台管理系统》该项目采用的技术实现如下:HTML+CSS+JavaScript+jsp+SpringBoot+Mybatis+Mysql


后台使用SpringBoot+mybatis框架

前端采用jsp+js+css等界面非常的美观大方

mysql数据库+tomcat服务器

(2)管理员功能介绍:

1、管理员登录(如果验证码错误报:验证码有误,密码或账户错误报账户或密码错误)


2、强制登录,如果管理员没有登录,不能进入系统(显示管理员名字为登录成功)


3、退出登录(注销Session的形式进行退出登录)

image.pngimage.png





(3)水果功能介绍:

1、分页展示所有


2、删除


3、批量删除


4、全选


6、修改(先进行数据回显之后进行修改)


7、图片上传和图片在页面显示功能


image.pngimage.pngimage.png






二、数据库设计

(1)数据库创建

-- 创建员工表
create table admin(
id int primary key auto_increment,
username varchar(20) not null,
password varchar(20) not null
)
-- 添加管理员数据
insert into admin values(null,'王恒杰','123456');
insert into admin values(null,'杨福君','whj63135');
insert into admin values(null,'邓正武','675437');
-- 查询管理员
select *from admin;
-- 创建水果表
create table fruit(
id int primary key auto_increment,
image varchar(30) not null,
name varchar(20) not null,
price double not null,
month int not null,
createTime date
);
-- 查询水果表
select * from fruit;
-- 添加水果信息
insert into fruit values(null,'/img.jpg','苹果','5.00',5,NOW());

(2)数据库设计文档

数据库名: fruitmall


文档版本: V1.0.0


文档描述: 数据库表设计描述



image.png

表名: admin


说明: 管理员



image.png

表名: fruit


说明: 水果


image.png

三、导入项目相关依赖和配置application.yml

(1)导入相关依赖

  <!--集成springboot的父项目-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
    </parent>
    <dependencies>
        <!--引入springboot的web依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--引入mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.16</version>
        </dependency>
        <!--引入mybatis以及整合相关依赖-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.2</version>
        </dependency>
        <!--druid-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.12</version>
        </dependency>
        <!--JSTL表达式-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!--引入junit测试相关依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <!--引入aop相关依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <!--jsp-->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
    </dependencies>

(2)配置application.yml

server:
  port: 8080 #端口号
  servlet:
    context-path: /fruitmall #水果商城
    jsp:
      init-parameters:
        development: true  #开启jsp页面的调试模式
spring:
  mvc:
    view:
      prefix: /    #前缀
      suffix: .jsp  #后缀
# 数据源
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource  #数据源类型
    driver-class-name: com.mysql.cj.jdbc.Driver   #加载驱动
    url: jdbc:mysql://localhost:3306/fruitmall?useSSL=false&serverTimezone=UTC
    username: root
    password: root
mybatis:
  mapper-locations: classpath:com/tjcu/mapper/*Mapper.xml #指定mapper文件所在的位置,其中classpath必须和mapper-locations分开
  type-aliases-package: com.tjcu.entity

四、管理员核心功能

1、前端

<%@page isELIgnored="false" contentType="text/html; harset=utf-8" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>login</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.min.css"/>
</head>
<body>
<div id="wrap" class="container-fluid">
    <div id="top_content" class="row" style="margin: 0 auto;">
        <div class="col-sm-8 col-sm-offset-2">
            <div id="header">
                <div id="topheader">
                    <h1 class="text-center text-info">欢迎进入水果管理系统V1.0</h1>
                </div>
                <div id="navigation">
                </div>
            </div>
        </div>
    </div>
    <div class="row" style="margin-top: 20px;">
        <div class="col-sm-8 col-sm-offset-2">
            <div id="content">
                <form method="post" action="${pageContext.request.contextPath}/admin/login">
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input type="text" v-model="username" id="username" class="form-control" name="username"/>
                    </div>
                    <div class="form-group">
                        <label for="password">密码</label>
                        <input type="password" id="password" v-model="password" class="form-control" name="password"/>
                    </div>
                    <br>
                    <tr>
                        <td valign="middle" align="right">
                            验证码:
                            <img id="num" src="${pageContext.request.contextPath}/admin/generateImageCode" />
                            <a href="javascript:;" onclick="document.getElementById('num').src = '${pageContext.request.contextPath}/admin/generateImageCode?'+(new Date()).getTime()">换一张</a>
                        </td>
                        <td valign="middle" align="left">
                            <input type="text" class="inputgri" name="adminCode" />
                        </td>
                    </tr>
                    <input type="submit" style="width: 98%" class="btn btn-danger" value="登录&raquo;"/>
                </form>
            </div>
            ${requestScope.msg}
        </div>
    </div>
    <div class="row" style="margin-top: 40px;">
        <div class="col-sm-8 col-sm-offset-2">
            <h5 class="text-center">Fruit@136.com</h5>
        </div>
    </div>
</div>
</body>
</html>

2、控制层

package com.tjcu.controller;
import com.tjcu.entity.Admin;
import com.tjcu.service.AdminService;
import com.tjcu.utils.VerifyCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import static javax.swing.text.html.CSS.getAttribute;
/**
 * @author 王恒杰
 * @date 2021/11/28 16:22
 * @Description:
 */
@Controller
@RequestMapping("admin")
public class AdminAction {
    @Autowired
    private AdminService adminService;
    @RequestMapping("login")
    public String login(Admin admin, HttpServletRequest request,String adminCode){
        //1.比较验证是否一致
        HttpSession session = request.getSession();
        String code = session.getAttribute("code").toString();
        if(code.equals(adminCode)){
            Admin login = adminService.login(admin.getUsername(), admin.getPassword());
           if(login!=null){
               request.setAttribute("admin",login);
               session.setAttribute("admin",login);
               return "forward:/fruit/showAll?pageNumber=1";
           }else {
               request.setAttribute("msg","用户名或者密码输入错误");
               return "login";
           }
        }else {
            request.setAttribute("msg","验证码输入错误");
            return "login";
        }
    }
    /**
     * 用来生成验证码方法
     */
    @RequestMapping("generateImageCode")
    public void generateImageCode(HttpSession session, HttpServletResponse response) throws IOException {
        //1.生成随机字符串
        String code = VerifyCodeUtils.generateVerifyCode(4);
        //2.保存随机字符串到Session中
        session.setAttribute("code",code);
        //3.将随机字符串生成图片
        //4.通过response响应图片
        response.setContentType("image/png");//指定响应类型
        ServletOutputStream os = response.getOutputStream();
        VerifyCodeUtils.outputImage(80,30,os,code);
    }
@RequestMapping("cancel")
    public String cancel(HttpServletRequest request){
        request.getSession().invalidate();
        request.setAttribute("msg","管理员已经退出登录!");
        return "login";
    }
}

五、水果相关功能核心代码

1、全选jquery实现

<script>
    $("#selectAll").click(function () {
        //:checkbox 获取当前选中的单选按钮或者复选框
        //:checkbox:gt(0) 获取当前复选框大于0的复选框
        //prop修改标签的属性 标签对象.prop(“属性名”,”属性值”);
        //prop获取标签的属性 标签对象.prop(“属性名”);
        //checked:选中
        //注意:在单选框和复选框中checked只要出现checked就是选中,不管他是否等于true还是false
        $(":checkbox:gt(0)").prop("checked",$("#selectAll").prop("checked"))
    })

2、确认删除jquery实现

<%--单个删除--%>
<script>
        function delRow(id,pageNumber){
            if(window.confirm("你确定删除这个商品吗?")){
                location.href="${pageContext.request.contextPath}/fruit/drop?pageNumber="+pageNumber+"&id="+id;
            }
        }
</script>

3、修改和数据回显前端页面

<%@page isELIgnored="false" contentType="text/html; harset=utf-8" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
\
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>update</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.min.css"/>
</head>
<body>
<div id="wrap">
    <div id="top_content" class="row" style="margin: 0 auto;">
        <div class="col-sm-8 col-sm-offset-2">
            <div id="header">
                <div id="topheader">
                    <h1 class="text-center text-info">欢迎进入水果管理系统V1.0</h1>
                </div>
                <div id="navigation">
                </div>
            </div>
        </div>
    </div>
    <div class="row" style="margin-top: 20px;">
        <div class="col-sm-8 col-sm-offset-2">
            <div id="content">
                <p id="whereami">
                </p>
                <h1>
                    修改水果信息:
                </h1>
                <form action="${pageContext.request.contextPath}/fruit/update" method="post" enctype="multipart/form-data">
                    <input  type="hidden" name="id" value="${requestScope.fruit.id}">
                    <div class="form-group">
                        <label for="name">名称</label>
                        <input type="text" class="form-control" name="name" id="name" value="${requestScope.fruit.name}"
                               placeholder="输入水果名称">
                    </div>
                    <div class="form-group">
                        <label for="price">价格</label>
                        <input type="text" class="form-control" name="price" id="price"
                               value="${requestScope.fruit.price}" placeholder="输入水果价格">
                    </div>
                    <div class="form-group">
                        <label for="age">保质期(单位:月)</label>
                        <input type="text" class="form-control"  id="age" name="month"
                               value="${requestScope.fruit.month}" placeholder="输入水果保质期">
                    </div>
                    <div class="form-group">
                        <label for="photos">水果图片</label>
                        <input type="file" ref="file" id="photos" class="form-control" name="photo"/>
                    </div>
                    <input type="submit"  style="width: 98%" class="btn btn-warning" value="确认修改" />
                </form>
            </div>
        </div>
    </div>
    <div id="footer">
        <div class="row" style="margin-top: 40px;">
            <div class="col-sm-8 col-sm-offset-2">
                <h5 class="text-center">Fruit@136.com</h5>
            </div>
        </div>
    </div>
</div>
</body>
</html>

4、分页前端页面实现

     <%--colspan:跨列数--%>
                        <td colspan="7" align="center">
                            <c:if test="${requestScope.pageNumber>1}">
                                <a href="${pageContext.request.contextPath}/fruit/showAll?pageNumber=${requestScope.pageNumber-1}">上一页</a>
                            </c:if>
                            <c:if test="${requestScope.pageNumber<=1}">
                                上一页
                            </c:if>
                            <%--当前页数--%>
                            <c:forEach begin="1" end="${requestScope.totalPage}" var="page">
                                <a href="${pageContext.request.contextPath}/fruit/showAll?pageNumber=${page}">${page}</a>
                            </c:forEach>
                            <%--下一页数--%>
                            <c:if test="${requestScope.pageNumber<requestScope.totalPage}">
                                <a href="${pageContext.request.contextPath}/fruit/showAll?pageNumber=${requestScope.pageNumber+1}">下一页</a>
                            </c:if>
                            <c:if test="${requestScope.pageNumber>=requestScope.totalPage}">
                                下一页
                            </c:if>
                        </td>
                    </tr>

5、Controller层

/**
 * @author 王恒杰
 * @date 2021/11/27 23:38
 * @Description:
 */
@Controller
@RequestMapping("fruit")
public class FruitAction {
    @Autowired
    private FruitService fruitService;
    /**
     * 添加水果
     */
    @RequestMapping("add")
    public String add(MultipartFile photo, Fruit fruit,HttpServletRequest request) throws IOException {
        //获取文件存储的真实路径
        String realPath = request.getSession().getServletContext().getRealPath("photo");
        //文件拷贝
        photo.transferTo(new File(realPath,photo.getOriginalFilename()));
        //水果的图片名
        fruit.setImg(photo.getOriginalFilename());
        fruitService.add(fruit);
        return "redirect:/fruit/showAll?pageNumber=1";
    }
    /**
     * 修改水果
     */
    @RequestMapping("update")
    public String update(MultipartFile photo, Fruit fruit,HttpServletRequest request) throws IOException {
        //获取文件存储的真实路径
        String realPath = request.getSession().getServletContext().getRealPath("photo");
        //文件拷贝
        photo.transferTo(new File(realPath+"/"+photo.getOriginalFilename()));
        //水果的图片名
        fruit.setImg(photo.getOriginalFilename());
        //修改时间
        fruit.setCreatTime(new Date());
        fruitService.update(fruit);
        return "redirect:/fruit/showAll?pageNumber=1";
    }
    /**
     * 查询水果 数据回显
     */
    @RequestMapping("query")
    public String query(Integer id, HttpServletRequest request) {
        System.out.println(id);
        Fruit query = fruitService.query(id);
        System.out.println(query);
        request.setAttribute("fruit", query);
        return "update";
    }
    /**
     * 删除水果
     */
    @RequestMapping("drop")
    public String drop(Fruit fruit,Integer pageNumber) {
        System.out.println(pageNumber);
        System.out.println(fruit.getId());
        fruitService.drop(fruit.getId());
        return "redirect:/fruit/showAll?pageNumber="+pageNumber;
    }
    /**
     * 批量删除
     */
    @RequestMapping("batchDelete")
    public String batchDelete(Collection collection) {
        fruitService.batchDelete(collection.getIds());
        return "redirect:/fruit/showAll?pageNumber=1";
    }
    /**
     * 分页实现
     */
    @RequestMapping("showAll")
    public String pageFruit(Integer pageNumber,HttpServletRequest request) {
        List<Fruit> fruits = fruitService.pageFruit(pageNumber);
        request.setAttribute("fruits",fruits);
        //当前页
        request.setAttribute("pageNumber",pageNumber);
        //总页数
        Integer integer = fruitService.TotalPage();
        request.setAttribute("totalPage",integer);
        return "showAll";
    }
}

六、源码下载及使用攻略

源码已经上传到gitee上面了,


原创不易,如果觉得不错请给我一个三连、点赞、收藏、加关注!!!


需要源码资料的同学可以去我gitee的下载源码


gitee地址:《SpringBoot水果商城后台管理系统》下载相关源码


相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
6天前
|
JavaScript 安全 Java
基于springboot的摄影器材租赁回收系统
本系统基于Java、Spring Boot与Vue技术,构建摄影器材租赁回收平台,解决市场不规范、资源浪费等问题。支持在线预约、信用免押、智能评估等功能,提升器材利用率,降低用户成本,推动行业绿色可持续发展。
|
2天前
|
JavaScript Java 关系型数据库
基于springboot的小区车位租售管理系统
针对城市化进程中小区停车难问题,本文设计基于SpringBoot的车位租售管理系统,结合Vue前端与MySQL数据库,实现车位信息数字化、租售流程自动化。系统支持在线查询、申请、支付及数据统计,提升管理效率与用户体验,促进资源优化配置。
|
9天前
|
前端开发 安全 Java
基于springboot+vue开发的会议预约管理系统
一个完整的会议预约管理系统,包含前端用户界面、管理后台和后端API服务。 ### 后端 - **框架**: Spring Boot 2.7.18 - **数据库**: MySQL 5.6+ - **ORM**: MyBatis Plus 3.5.3.1 - **安全**: Spring Security + JWT - **Java版本**: Java 11 ### 前端 - **框架**: Vue 3.3.4 - **UI组件**: Element Plus 2.3.8 - **构建工具**: Vite 4.4.5 - **状态管理**: Pinia 2.1.6 - **HTTP客户端
85 4
基于springboot+vue开发的会议预约管理系统
|
19天前
|
前端开发 NoSQL Java
基于Spring Boot + Vue3的办公用品申领管理系统
这是一个基于Spring Boot和Vue3的办公用品申领系统,支持用户申请、管理员审批及库存管理等功能,技术涵盖JWT认证、Redis缓存与Element Plus组件库,提供完整的前后端解决方案。
64 1
基于Spring Boot + Vue3的办公用品申领管理系统
|
8天前
|
监控 JavaScript Java
基于springboot的游乐园管理系统
本系统基于SpringBoot与Vue技术,构建高效、智能的游乐园管理系统,实现票务电子化、设备监控智能化、员工管理自动化,提升运营效率与游客体验,推动游乐园数字化转型与智慧升级。
|
6天前
|
JavaScript Java 关系型数据库
基于springboot的旅游门票预定系统
在数字化时代,旅游门票预定系统应运而生,结合Spring Boot、Vue、Java与MySQL技术,实现在线预订、电子验票、数据分析等功能,提升游客体验与景区管理效率,推动旅游业智能化转型。
|
6天前
|
搜索推荐 算法 JavaScript
基于springboot的健康饮食营养管理系统
本系统基于Spring Boot、Vue与MySQL技术,融合大数据与AI算法,构建个性化健康饮食管理平台。结合用户身体状况、目标需求,智能推荐营养方案,助力科学饮食与健康管理。
|
6天前
|
JavaScript 前端开发 Java
基于springboot的4s店汽车试驾销售服务系统
针对传统4S店运营效率低、服务体验差等问题,研究基于SpringBoot的汽车销售服务系统,融合Java、Vue、MySQL等技术,实现业务自动化、客户个性化服务与数据智能分析,提升管理效率与客户满意度,推动4S店数字化转型与竞争力升级。
|
7天前
|
JavaScript 安全 Java
基于springboot的大学生心理咨询管理系统
本研究针对大学生心理健康问题,构建基于Spring Boot、Vue等技术的心理咨询管理系统,实现心理数据电子化、智能化管理。系统支持在线预约、匿名咨询、心理测评与数据分析,兼具隐私保护与危机预警功能,提升服务可及性与干预精准度,助力高校心理健康工作科学化发展。
|
8天前
|
供应链 JavaScript Java
基于springboot的半成品配菜管理系统
本研究基于SpringBoot框架构建半成品配菜管理系统,旨在解决行业库存、订单与供应链管理难题。系统实现库存预警、订单自动化与供应链协同,提升企业效率与客户满意度,推动行业信息化、智能化发展,具有重要现实意义与应用价值。(238字)