当前位置:   article > 正文

Spring Boot项目实例——简易版商城管理系统_spring 简易商城

spring 简易商城

概述

通过对三张表的CRUD,将相应的操作结果渲染到页面上。
如果想查看SSM架构的同等规模的项目,可参考此篇博客SSM项目实例——简易版图书管理系统
为了更好地讲解整个项目,与上篇博客不同的是,我将代码的实现部分分为后台部分前台部分,作为一个更好的区分。
在讲解中,若在标题中标示出“扩展”,即该部分是项目的拓展部分,如果想要运行整个项目也可以不进行添加,这里根据需求使用即可。
末尾的后记部分有源码地址,读者可参考。

准备

  • 环境
    • IDEA
    • MySQL 5.7.19
    • Tomcat 9
    • Maven 3.6
    • Spring Boot
    • Mybatis
    • Thymeleaf
    • BootStrap
    • JQuery(没有正式使用,可以根据需求进行改进)
  • 要求
    • 掌握MySQL数据库
    • 掌握Spring Boot的使用
    • 掌握Mybatis的使用
    • 掌握yaml格式的配置文件
    • 掌握Thymeleaf模板引擎的使用
    • 掌握进阶的前端知识

流程图

为了便于大家更好理解,这里给出一幅自画的流程图,供读者参考
在这里插入图片描述

实现

后台部分

1.搭建数据库

  1. 创建一个存放数据的数据库(smms),并在该数据库中建立三张表:user(用户)、orders(订单)、goods(商品),并且添加一些数据,其中需要特别说明的是,orders表中的order_userid作为user表中user_id的外键字段,goods表中的goods_id作为orders表中的order_id的外键字段,代码如下:
-- MySQL dump 10.13  Distrib 5.7.19, for Win64 (x86_64)
--
-- Host: 127.0.0.1    Database: smms
-- ------------------------------------------------------
-- Server version	5.7.19

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `goods`
--

DROP TABLE IF EXISTS `goods`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `goods` (
  `goods_id` int(11) NOT NULL AUTO_INCREMENT,
  `goods_name` varchar(20) NOT NULL,
  `goods_description` varchar(255) DEFAULT NULL,
  `goods_count` int(11) DEFAULT NULL,
  `goods_orderid` int(11) DEFAULT NULL,
  PRIMARY KEY (`goods_id`) USING BTREE,
  KEY `fk_goods_order` (`goods_orderid`) USING BTREE,
  CONSTRAINT `fk_goods_order` FOREIGN KEY (`goods_orderid`) REFERENCES `orders` (`order_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `goods`
--

LOCK TABLES `goods` WRITE;
/*!40000 ALTER TABLE `goods` DISABLE KEYS */;
INSERT INTO `goods` VALUES (3,'kkkk','123',123,14);
/*!40000 ALTER TABLE `goods` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `orders`
--

DROP TABLE IF EXISTS `orders`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `orders` (
  `order_id` int(11) NOT NULL AUTO_INCREMENT,
  `order_name` varchar(20) NOT NULL,
  `order_date` date DEFAULT NULL,
  `order_userid` int(11) DEFAULT NULL,
  PRIMARY KEY (`order_id`) USING BTREE,
  KEY `fk_order_user` (`order_userid`) USING BTREE,
  CONSTRAINT `fk_order_user` FOREIGN KEY (`order_userid`) REFERENCES `user` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `orders`
--

LOCK TABLES `orders` WRITE;
/*!40000 ALTER TABLE `orders` DISABLE KEYS */;
INSERT INTO `orders` VALUES (14,'莫息涛','2020-03-02',11);
/*!40000 ALTER TABLE `orders` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `user`
--

DROP TABLE IF EXISTS `user`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_name` varchar(20) NOT NULL DEFAULT '',
  `user_passwd` varchar(20) NOT NULL,
  `user_ismanager` int(11) DEFAULT NULL,
  PRIMARY KEY (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `user`
--

LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` VALUES (11,'1234','123',1),(12,'1234','123',0),(13,'4321','321',0),(14,'1234','123',0),(16,'123456789','abcdefg',0),(17,'1234','123',0);
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2020-03-23 17:30:22

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  1. 保证IDEA中可以连接到MySql,并且在Database预览卡中能够查看其中的数据,如图所示:
    在这里插入图片描述

2.依赖管理

通过IDEA新建一个Spring Boot项目,然后再pom.xml文件中导入相应的依赖,代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.project</groupId>
    <artifactId>smms</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>smms</name>
    <description>万象母婴店务营销管理系统</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!--Spring Boot的Web依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--Spring Boot的测试依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--导入配置文件处理器,配置文件进行绑定就会有提示-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

        <!--JDBC和Mysql驱动-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- 引入 myBatis,这是 MyBatis官方提供的适配 Spring Boot 的,而不是Spring Boot自己的-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.0</version>
        </dependency>

        <!--thymeleaf页面模板-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84

3.配置文件

修改resouces目录下的application.properties/application.yaml,这里选用yaml格式的配置文件,首先配置数据源,然后禁用thymeleaf模板引擎中的缓存,最后再配置mybatis的实体类映射路径以及mapper的存放路径,其中所有的路径可以根据实际的项目需要来进行修改,代码如下:

spring:
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://localhost:3306/smms?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
    driver-class-name: com.mysql.cj.jdbc.Driver
  thymeleaf:
    cache: false
mybatis:
  mapper-locations: classpath:mappers/*.xml
  type-aliases-package: com.project.smms.pojo
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

4.实现pojo层

  1. 在项目的包下新建一个pojo包,用于存放实体类,并在其中新增User类,对应数据库中的user表,代码如下:
package com.project.smms.pojo;

/**
 * @author 莫息涛
 * @Description: 用户的实体类
 * @date 2020/3/5 16:09
 */
public class User {

    /**
     * 用户id
     */
    private int user_id;

    /**
     * 用户名
     */
    private String user_name;

    /**
     * 用户密码
     */
    private String user_passwd;

    /**
     * 用户是否是管理员,1代表是,0代表否
     */
    private int user_ismanager;

    public User() {
    }

    public User(int user_id, String user_name, String user_passwd, int user_ismanager) {
        this.user_id = user_id;
        this.user_name = user_name;
        this.user_passwd = user_passwd;
        this.user_ismanager = user_ismanager;
    }

    public int getUser_id() {
        return user_id;
    }

    public void setUser_id(int user_id) {
        this.user_id = user_id;
    }

    public String getUser_name() {
        return user_name;
    }

    public void setUser_name(String user_name) {
        this.user_name = user_name;
    }

    public String getUser_passwd() {
        return user_passwd;
    }

    public void setUser_passwd(String user_passwd) {
        this.user_passwd = user_passwd;
    }

    public int getUser_ismanager() {
        return user_ismanager;
    }

    public void setUser_ismanager(int user_ismanager) {
        this.user_ismanager = user_ismanager;
    }

    @Override
    public String toString() {
        return "User{" +
                "user_id=" + user_id +
                ", user_name='" + user_name + '\'' +
                ", user_passwd='" + user_passwd + '\'' +
                ", user_ismanager=" + user_ismanager +
                '}';
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  1. 在pojo包中新增Order类,对应数据库中的orders表,代码如下:
package com.project.smms.pojo;

import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * @author 莫息涛
 * @Description: 订单的实体类
 * @date 2020/3/5 16:08
 */
public class Order {

    /**
     * 订单id
     */
    private int order_id;

    /**
     * 订单名称
     */
    private String order_name;

    /**
     * 订单日期
     */
    @DateTimeFormat(pattern="yyyy-MM-dd")
    private Date order_date;

    /**
     * 订单的用户id
     */
    private int order_userid;

    public Order() {
    }

    public Order(int order_id, String order_name, Date order_date, int order_userid) {
        this.order_id = order_id;
        this.order_name = order_name;
        this.order_date = order_date;
        this.order_userid = order_userid;
    }

    public int getOrder_id() {
        return order_id;
    }

    public void setOrder_id(int order_id) {
        this.order_id = order_id;
    }

    public String getOrder_name() {
        return order_name;
    }

    public void setOrder_name(String order_name) {
        this.order_name = order_name;
    }

    public Date getOrder_date() {
        return order_date;
    }

    public void setOrder_date(Date order_date) {
        this.order_date = order_date;
    }

    public int getOrder_userid() {
        return order_userid;
    }

    public void setOrder_userid(int order_userid) {
        this.order_userid = order_userid;
    }

    @Override
    public String toString() {
        return "Order{" +
                "order_id=" + order_id +
                ", order_name='" + order_name + '\'' +
                ", order_date=" + order_date +
                ", order_userid=" + order_userid +
                '}';
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  1. 在pojo包中新增Goods类,对应数据库中的goods表,代码如下:
package com.project.smms.pojo;

import org.springframework.stereotype.Component;

/**
 * @author 莫息涛
 * @Description: 商品的实体类
 * @date 2020/3/5 15:55
 */
@Component
public class Goods {

    /**
     * 商品id
     */
    private int goods_id;

    /**
     * 商品名
     */
    private String goods_name;

    /**
     * 商品描述
     */
    private String goods_description;

    /**
     * 商品数量
     */
    private int goods_count;

    /**
     * 商品的订单id
     */
    private int goods_orderid;

    public Goods() {
    }

    public Goods(int goods_id, String goods_name, String goods_description, int goods_count, int goods_orderid) {
        this.goods_id = goods_id;
        this.goods_name = goods_name;
        this.goods_description = goods_description;
        this.goods_count = goods_count;
        this.goods_orderid = goods_orderid;
    }

    public int getGoods_id() {
        return goods_id;
    }

    public void setGoods_id(int goods_id) {
        this.goods_id = goods_id;
    }

    public String getGoods_name() {
        return goods_name;
    }

    public void setGoods_name(String goods_name) {
        this.goods_name = goods_name;
    }

    public String getGoods_description() {
        return goods_description;
    }

    public void setGoods_description(String goods_description) {
        this.goods_description = goods_description;
    }

    public int getGoods_count() {
        return goods_count;
    }

    public void setGoods_count(int goods_count) {
        this.goods_count = goods_count;
    }

    public int getGoods_orderid() {
        return goods_orderid;
    }

    public void setGoods_orderid(int goods_orderid) {
        this.goods_orderid = goods_orderid;
    }

    @Override
    public String toString() {
        return "Goods{" +
                "goods_id=" + goods_id +
                ", goods_name='" + goods_name + '\'' +
                ", goods_description='" + goods_description + '\'' +
                ", goods_count=" + goods_count +
                ", goods_orderid=" + goods_orderid +
                '}';
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99

5.实现dao层

  1. 在项目的包下新建一个dao包,用于存放数据操作层接口,并在其中新增UserMapper接口,代码如下:
package com.project.smms.dao;
import com.project.smms.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * @author 莫息涛
 * @Description: 用户的数据操作层接口
 * @date 2020/3/5 16:30
 */
@Mapper
@Repository
public interface UserMapper {

    /**
     * 查询所有用户
     * @return
     */
    List<User> selectUser();

    /**
     * 根据id查询用户
     * @param user_id
     * @return
     */
    User selectUserById(int user_id);

    /**
     * 添加一个用户
     * @param user
     * @return
     */
    int addUser(User user);

    /**
     * 修改一个用户
     * @param user
     * @return
     */
    int updateUser(User user);

    /**
     * 删除一个用户
     * @param user_id
     * @return
     */
    int deleteUser(int user_id);
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  1. 在dao包中新增OrderMapper接口,代码如下:
package com.project.smms.dao;
import com.project.smms.pojo.Order;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 莫息涛
 * @Description: 订单的数据操作层接口
 * @date 2020/3/6 15:58
 */
@Mapper
@Repository
public interface OrderMapper {

    /**
     * 查询所有订单
     * @return
     */
    List<Order> selectOrder();

    /**
     * 根据id查询订单
     * @param order_id
     * @return
     */
    Order selectOrderById(int order_id);

    /**
     * 添加一个订单
     * @param order
     * @return
     */
    int addOrder(Order order);

    /**
     * 修改一个订单
     * @param order
     * @return
     */
    int updateOrder(Order order);

    /**
     * 删除一个订单
     * @param order_id
     * @return
     */
    int deleteOrder(int order_id);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  1. 在dao包中新增GoodsMapper接口,代码如下:
package com.project.smms.dao;
import com.project.smms.pojo.Goods;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * @author 莫息涛
 * @Description: 商品的数据操作层接口
 * @date 2020/3/6 15:54
 */
@Mapper
@Repository
public interface GoodsMapper {

    /**
     * 查询所有商品
     * @return
     */
    List<Goods> selectGoods();

    /**
     * 根据id查询商品
     * @param goods_id
     * @return
     */
    Goods selectGoodsById(int goods_id);

    /**
     * 添加一个商品
     * @param goods
     * @return
     */
    int addGoods(Goods goods);

    /**
     * 修改一个商品
     * @param goods
     * @return
     */
    int updateGoods(Goods goods);

    /**
     * 删除一个商品
     * @param goods_id
     * @return
     */
    int deleteGoods(int goods_id);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  1. 在项目的resouces下新建一个mappers包,用于存放数据操作层的xml映射实现类,并在其中新增UserMapper.xml,代码如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.project.smms.dao.UserMapper">

    <select id="selectUser" resultType="com.project.smms.pojo.User">
        select * from user
    </select>

    <select id="selectUserById" resultType="com.project.smms.pojo.User">
        select * from user where user_id = #{user_id}
    </select>

    <insert id="addUser" parameterType="com.project.smms.pojo.User">
        insert into user (user_name,user_passwd,user_ismanager) values (#{user_name},#{user_passwd},#{user_ismanager})
    </insert>

    <update id="updateUser" parameterType="com.project.smms.pojo.User">
        update user set user_name=#{user_name},user_passwd=#{user_passwd},user_ismanager=#{user_ismanager} where user_id = #{user_id}
    </update>

    <delete id="deleteUser" parameterType="int">
        delete from user where user_id = #{user_id}
    </delete>
</mapper>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  1. 在resouces/mappers下新增OrderMapper.xml,代码如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.project.smms.dao.OrderMapper">

    <select id="selectOrder" resultType="com.project.smms.pojo.Order">
        select * from orders
    </select>

    <select id="selectOrderById" resultType="com.project.smms.pojo.Order">
        select * from orders where order_id = #{order_id}
    </select>

    <insert id="addOrder" parameterType="com.project.smms.pojo.Order">
        insert into orders (order_name,order_date,order_userid) values (#{order_name},#{order_date},#{order_userid})
    </insert>

    <update id="updateOrder" parameterType="com.project.smms.pojo.Order">
        update orders set order_name=#{order_name},order_date=#{order_date},order_userid=#{order_userid} where order_id = #{order_id}
    </update>

    <delete id="deleteOrder" parameterType="int">
        delete from orders where order_id = #{order_id}
    </delete>
</mapper>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  1. 在resouces/mappers下新增GoodsMapper.xml,代码如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.project.smms.dao.GoodsMapper">

    <select id="selectGoods" resultType="com.project.smms.pojo.Goods">
        select * from goods
    </select>

    <select id="selectGoodsById" resultType="com.project.smms.pojo.Goods">
        select * from goods where goods_id = #{goods_id}
    </select>

    <insert id="addGoods" parameterType="com.project.smms.pojo.Goods">
        insert into goods (goods_name,goods_description,goods_count,goods_orderid) values (#{goods_name},#{goods_description},#{goods_count},#{goods_orderid})
    </insert>

    <update id="updateGoods" parameterType="com.project.smms.pojo.Goods">
        update goods set goods_name= #{goods_name},goods_description= #{goods_description},goods_count=#{goods_count},goods_orderid=#{goods_orderid} where goods_id = #{goods_id}
    </update>

    <delete id="deleteGoods" parameterType="int">
        delete from goods where goods_id = #{goods_id}
    </delete>

</mapper>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

6.实现service层

  1. 在项目的包下新建一个service包,用于存放数据操作层接口,并在其中新增UserService接口,代码如下:
package com.project.smms.service;
import com.project.smms.pojo.User;

import java.util.List;

/**
 * @author 莫息涛
 * @Description: 用户的服务层接口
 * @date 2020/3/5 16:30
 */
public interface UserService {

    /**
     * 查询所有用户
     * @return
     */
    List<User> selectUser();

    /**
     * 根据id查询用户
     * @param user_id
     * @return
     */
    User selectUserById(int user_id);

    /**
     * 添加一个用户
     * @param user
     * @return
     */
    int addUser(User user);

    /**
     * 修改一个用户
     * @param user
     * @return
     */
    int updateUser(User user);

    /**
     * 删除一个用户
     * @param user_id
     * @return
     */
    int deleteUser(int user_id);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  1. 在service包中新增OrderService接口,代码如下:
package com.project.smms.service;

import com.project.smms.pojo.Order;

import java.util.List;

/**
 * @author 莫息涛
 * @Description: 订单的服务层接口
 * @date 2020/3/6 16:24
 */
public interface OrderService {

    /**
     * 查询所有订单
     * @return
     */
    List<Order> selectOrder();

    /**
     * 根据id查询订单
     * @param order_id
     * @return
     */
    Order selectOrderById(int order_id);

    /**
     * 添加一个订单
     * @param order
     * @return
     */
    int addOrder(Order order);

    /**
     * 修改一个订单
     * @param order
     * @return
     */
    int updateOrder(Order order);

    /**
     * 删除一个订单
     * @param order_id
     * @return
     */
    int deleteOrder(int order_id);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  1. 在service包中新增GoodsService接口,代码如下:
package com.project.smms.service;

import com.project.smms.pojo.Goods;

import java.util.List;

/**
 * @author 莫息涛
 * @Description: 商品的服务层接口
 * @date 2020/3/6 16:21
 */
public interface GoodsService {

    /**
     * 查询所有商品
     * @return
     */
    List<Goods> selectGoods();

    /**
     * 根据id查询商品
     * @param goods_id
     * @return
     */
    Goods selectGoodsById(int goods_id);

    /**
     * 添加一个商品
     * @param goods
     * @return
     */
    int addGoods(Goods goods);

    /**
     * 修改一个商品
     * @param goods
     * @return
     */
    int updateGoods(Goods goods);

    /**
     * 删除一个商品
     * @param goods_id
     * @return
     */
    int deleteGoods(int goods_id);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  1. 在service包下新建一个impl包,用于存放服务层的实现类,并在其中新增UserServiceImpl,注意要在实现类中添加Spring的相关注解,而不是在接口,代码如下:
package com.project.smms.service.impl;

import com.project.smms.dao.UserMapper;
import com.project.smms.pojo.User;
import com.project.smms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 莫息涛
 * @Description: 用户的服务层实现类
 * @date 2020/3/5 16:31
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> selectUser() {
        return userMapper.selectUser();
    }

    @Override
    public User selectUserById(int user_id) {
        return userMapper.selectUserById(user_id);
    }

    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public int deleteUser(int user_id) {
        return userMapper.deleteUser(user_id);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  1. 在service/impl下新增OrderServiceImpl,代码如下:
package com.project.smms.service.impl;
import com.project.smms.dao.OrderMapper;
import com.project.smms.pojo.Order;
import com.project.smms.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 莫息涛
 * @Description: 订单的服务层实现类
 * @date 2020/3/6 16:25
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Order> selectOrder() {
        return orderMapper.selectOrder();
    }

    @Override
    public Order selectOrderById(int order_id) {
        return orderMapper.selectOrderById(order_id);
    }

    @Override
    public int addOrder(Order order) {
        return orderMapper.addOrder(order);
    }

    @Override
    public int updateOrder(Order order) {
        return orderMapper.updateOrder(order);
    }

    @Override
    public int deleteOrder(int order_id) {
        return orderMapper.deleteOrder(order_id);
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  1. 在service/impl下新增GoodsServiceImpl,代码如下:
package com.project.smms.service.impl;

import com.project.smms.dao.GoodsMapper;
import com.project.smms.pojo.Goods;
import com.project.smms.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 莫息涛
 * @Description: 商品的服务层实现类
 * @date 2020/3/6 16:21
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<Goods> selectGoods() {
        return goodsMapper.selectGoods();
    }

    @Override
    public Goods selectGoodsById(int goods_id) {
        return goodsMapper.selectGoodsById(goods_id);
    }

    @Override
    public int addGoods(Goods goods) {
        return goodsMapper.addGoods(goods);
    }

    @Override
    public int updateGoods(Goods goods) {
        return goodsMapper.updateGoods(goods);
    }

    @Override
    public int deleteGoods(int goods_id) {
        return goodsMapper.deleteGoods(goods_id);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

7.实现controller层

  1. 在项目的包下新建一个controller包,用于存放控制层接口,并在其中新增LoginController,代码如下:
package com.project.smms.controller;
import com.project.smms.pojo.User;
import com.project.smms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 莫息涛
 * @Description: 登录相关的控制器
 * @date 2020/3/5 17:40
 */
@Controller
public class LoginController {

    @Autowired
    private UserService userService;

    @RequestMapping("/toLogin")
    public String toLogin(Model model){
        model.addAttribute("user",new User());
        return "login";
    }

    @RequestMapping("/checkUser")
    public String checkUser(@ModelAttribute User user, HttpServletRequest request){
        String userName = user.getUser_name();
        String passWord = user.getUser_passwd();
        List<User> users = userService.selectUser();
        for (User tempuser : users) {
            if (tempuser.getUser_name().equals(userName) & tempuser.getUser_passwd().equals(passWord)){
                HttpSession session = request.getSession();
                session.setAttribute("user",user);
                return "index";
            }
        }
        return "error";
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  1. 在controller下新增UserController,代码如下:
package com.project.smms.controller;

import com.project.smms.pojo.User;
import com.project.smms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Collection;


/**
 * @author 莫息涛
 * @Description: 用户的控制器
 * @date 2020/3/5 19:44
 */
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/selectUser")
    public String selectUser(Model model){
        Collection<User> users = userService.selectUser();
        model.addAttribute("users",users);
        return "user";
    }

    @RequestMapping("/deleteUser/{user_id}")
    public String deleteUser(@PathVariable("user_id") Integer id,Model model){
        try {
            userService.deleteUser(id);
        }catch (Exception e){
            return "errordata";
        }finally {
            Collection<User> users = userService.selectUser();
            model.addAttribute("users",users);
        }
        return "user";
    }

    @RequestMapping("/toAddPage")
    public String toAddPage(){
        return "adduser";
    }


    @RequestMapping("/addUser")
    public String addUser(User user, Model model){
        try {
            userService.addUser(user);
        }catch (Exception e){
            return "errordata";
        }finally {
            Collection<User> users = userService.selectUser();
            model.addAttribute("users",users);
        }
        return "user";
    }

    @RequestMapping("/toUpdatePage/{user_id}")
    public String toUpdatePage(@PathVariable("user_id") Integer id,Model model){
        User user = userService.selectUserById(id);
        model.addAttribute("updateuser",user);
        return "updateuser";
    }

    @RequestMapping("/updateUser")
    public String updateUser(User user,Model model){
        try {
            userService.updateUser(user);
        }catch (Exception e){
            return "errordata";
        }finally {
            Collection<User> users = userService.selectUser();
            model.addAttribute("users",users);
        }
        return "user";
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  1. 在controller下新增OrderController,代码如下:
package com.project.smms.controller;

import com.project.smms.pojo.Order;
import com.project.smms.pojo.User;
import com.project.smms.service.OrderService;
import com.project.smms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Collection;
import java.util.List;

/**
 * @author 莫息涛
 * @Description: 订单的控制器
 * @date 2020/3/6 16:28
 */
@Controller
public class OrderController {

    @Autowired
    private OrderService orderService;
    
    @Autowired
    private UserService userService;

    @RequestMapping("/selectOrder")
    public String selectOrder(Model model){
        Collection<Order> orders = orderService.selectOrder();
        model.addAttribute("orders",orders);
        return "order";
    }

    @RequestMapping("/deleteOrder/{order_id}")
    public String deleteOrder(@PathVariable("order_id") Integer id, Model model){
        try {
            orderService.deleteOrder(id);
        }catch (Exception e){
            return "errordata";
        }finally {
            Collection<Order> orders = orderService.selectOrder();
            model.addAttribute("orders",orders);
        }
        return "order";
    }

    @RequestMapping("/toAddOrderPage")
    public String toAddPage(Model model){
        List<User> users = userService.selectUser();
        model.addAttribute("ordersuser",users);
        return "addorder";
    }

    @RequestMapping("/addOrder")
    public String addOrder(Order order, Model model){
        try {
            orderService.addOrder(order);
        }catch (Exception e){
            return "errordata";
        }finally {
            Collection<Order> orders = orderService.selectOrder();
            model.addAttribute("orders",orders);
        }
        return "order";
    }

    @RequestMapping("/toUpdateOrderPage/{order_id}")
    public String toUpdatePage(@PathVariable("order_id") Integer id,Model model){
        Order order = orderService.selectOrderById(id);
        List<User> users = userService.selectUser();
        model.addAttribute("ordersuser",users);
        model.addAttribute("updateorder",order);
        return "updateorder";
    }

    @RequestMapping("/updateOrder")
    public String updateOrder(Order order, Model model){
        try {
            orderService.updateOrder(order);
        }catch (Exception e){
            return "errordata";
        }finally {
            Collection<Order> orders = orderService.selectOrder();
            model.addAttribute("orders",orders);
        }
        return "order";
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  1. 在controller下新增GoodsController,代码如下:
package com.project.smms.controller;

import com.project.smms.pojo.Goods;
import com.project.smms.pojo.Order;
import com.project.smms.service.GoodsService;
import com.project.smms.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Collection;
import java.util.List;

/**
 * @author 莫息涛
 * @Description: 商品的控制层
 * @date 2020/3/7 15:11
 */
@Controller
public class GoodsController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private GoodsService goodsService;

    @RequestMapping("/selectGoods")
    public String selectGoods(Model model){
        Collection<Goods> goods = goodsService.selectGoods();
        model.addAttribute("goods",goods);
        return "goods";
    }

    @RequestMapping("/deleteGoods/{goods_id}")
    public String deleteGoods(@PathVariable("goods_id") Integer id, Model model){
        try {
            goodsService.deleteGoods(id);
        }catch (Exception e){
            return "errordata";
        }finally {
            Collection<Goods> goods = goodsService.selectGoods();
            model.addAttribute("goods",goods);
        }
        return "goods";
    }

    @RequestMapping("/toAddGoodsPage")
    public String toAddPage(Model model){
        List<Order> order = orderService.selectOrder();
        model.addAttribute("ordergoods",order);
        return "addgoods";
    }

    @RequestMapping("/addGoods")
    public String addGoods(Goods goods, Model model){
        try {
            goodsService.addGoods(goods);
        }catch (Exception e){
            return "errordata";
        }finally {
            Collection<Goods> goods1 = goodsService.selectGoods();
            model.addAttribute("goods",goods1);
        }
        return "goods";
    }

    @RequestMapping("/toUpdateGoodsPage/{goods_id}")
    public String toUpdatePage(@PathVariable("goods_id") Integer id,Model model){
        List<Order> order = orderService.selectOrder();
        Goods goods = goodsService.selectGoodsById(id);
        model.addAttribute("ordergoods",order);
        model.addAttribute("updategoods",goods);
        return "updategoods";
    }

    @RequestMapping("/updateGoods")
    public String updateGoods(Goods goods, Model model){
        try {
            goodsService.updateGoods(goods);
        }catch (Exception e){
            return "errordata";
        }finally {
            Collection<Goods> goods1 = goodsService.selectGoods();
            model.addAttribute("goods",goods1);
        }
        return "goods";
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91

8.实现component层(拓展)

在项目的包下新建一个component包,用于存放项目中用到的各种组件,并在其中新增LoginInterceptor,用于作为一个验证登录的拦截器,代码如下:

package com.project.smms.component;

import com.project.smms.pojo.User;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author 莫息涛
 * @Description: 登录相关的拦截器
 * @date 2020/3/11 16:35
 */
@Component
    public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        if (user == null){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

9.实现config层(拓展)

在项目的包下新建一个config包,用于存放项目中用到的一些配置文件,并在其中新增InterceptorConfig,用于作为一个拦截器的配置文件,代码如下:

package com.project.smms.config;

import com.project.smms.component.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 莫息涛
 * @Description: 登录相关的拦截器的配置类
 * @date 2020/3/11 16:35
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
        .excludePathPatterns("/toLogin","/checkUser","/toLogin/","/checkUser/","/**/*.css","/**/*.js");
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

10.实现utils层(拓展)

  1. 在项目的包下新建一个utils包,用于存放项目中用到的一些工具类,并在其中新增LogLevel,用于作为日志工具类的日志等级控制,代码如下:
package com.project.smms.utils.log;

/**
 * <pre>
 * 日志级别
 * ALL("全部", 0)
 * INFO("信息", 1)
 * WARN("警告", 2)
 * ERROR("错误", 3)
 * </pre>
 * 
 * @since 2018年4月9日 9:31:46
 * @author ygr
 */
public enum LogLevel {
    ALL("[]", 0), INFO("[INFO]", 1), WARN("[WARN]", 2), ERROR("[ERROR]", 3);

    private String name;
    private int level;

    LogLevel(String name, int level) {
        this.name = name;
        this.level = level;
    }

    public String getName() {
        return name;
    }

    public int getLevel() {
        return level;
    }
    /**
     * <pre>
     * 判断是否允许打印
     * </pre>
     * @author ygr
     * @date 2018年4月9日 上午9:36:47
     * @param minLevel 最低日志级别
     * @return
     */
    public boolean isAllow(LogLevel minLevel){
        if(level >= minLevel.getLevel()){
            return true;
        }

        return false;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  1. 在utils下新增LogUtils,作为日志输出的工具类,代码如下:
package com.project.smms.utils.log;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <pre>
 * 简单的日志工具类
 * </pre>
 * 
 * @since 2018年4月9日 上午9:30:12
 * @author ygr
 */
public class LogUtils {
    /** 默认可以打印 */
    private static boolean enable = true;
    /** 默认打印所有级别日志 */
    private static LogLevel minLevel = LogLevel.ALL;
    /** 日期显示格式 */
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");

    /**
     * <pre>
     * 设置是否开启打印
     * </pre>
     * 
     * @author ygr
     * @date 2018年4月9日 上午9:54:46
     * @param enable
     */
    public static void setEnable(boolean enable) {
        LogUtils.enable = enable;
    }
    /**
     * <pre>
     * 设置日志打印级别
     * </pre>
     * 
     * @author ygr
     * @date 2018年4月9日 上午9:42:09
     * @param level
     */
    public static void setLogLevel(LogLevel level) {
        LogUtils.minLevel = level;
    }

    /**
     * <pre>
     * 打印消息级别日志
     * </pre>
     * 
     * @author ygr
     * @date 2018年4月9日 上午9:42:59
     * @param msg
     *            待打印消息
     */
    public static void info(String msg) {
        finalPrint(LogLevel.INFO, msg);
    }

    /**
     * <pre>
     * 打印警告级别日志
     * </pre>
     * 
     * @author ygr
     * @date 2018年4月9日 上午9:42:59
     * @param msg
     *            待打印消息
     */
    public static void warn(String msg) {
        finalPrint(LogLevel.WARN, msg);
    }

    /**
     * <pre>
     * 打印错误级别日志
     * </pre>
     * 
     * @author ygr
     * @date 2018年4月9日 上午9:42:59
     * @param msg
     *            待打印消息
     */
    public static void error(String msg) {
        finalPrint(LogLevel.ERROR, msg);
    }

    /**
     * <pre>
     * 最终打印日志
     * </pre>
     * 
     * @author ygr
     * @date 2018年4月9日 上午9:50:21
     * @param logLevel
     *            日志级别
     * @param msg
     *            待打印消息
     */
    private static void finalPrint(LogLevel logLevel, String msg) {
        if (!enable) {
            return;
        }
        if (logLevel.isAllow(minLevel)) {
            System.out.printf("%s %s %s\n", formatCurrentTime(), logLevel.getName(), msg);
        }
    }

    /**
     * <pre>
     * 获取当前时间
     * </pre>
     * 
     * @author ygr
     * @date 2018年4月9日 上午9:49:00
     * @return
     */
    private static String formatCurrentTime() {
        return sdf.format(new Date());
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122

前台部分

1.引入BootStrap和JQuery

由于在项目里用到了BootStrap和JQuery,这里需要将它们引入到项目中,Spring Boot使用resources/static目录来存放静态文件,我们将这两个框架导到这里,如图所示:
在这里插入图片描述

2.实现View层

由于View层页面较多,这里进行一个细致的划分,以此来更好地陈列这些页面

1.登录页面 login.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>登录</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<h1>登录</h1>
<!--<form action="#" th:action="@{/checkUser}" th:object="${user}" method="post">-->
<!--    账号:<input type="text" th:field="*{user_name}" />-->
<!--    密码:<input type="text" th:field="*{user_passwd}" />-->
<!--    <input type="submit" />-->
<!--</form>-->
<body class="text-center">
    <form class="form-signin" action="#" th:action="@{/checkUser}" th:object="${user}" method="post">
        <h1 class="h3 mb-3 font-weight-normal">登录</h1>
        <label class="sr-only" >账号</label>
        <input type="text" class="form-control" placeholder="账号" required="" autofocus="" th:field="*{user_name}">
        <label class="sr-only" >密码</label>
        <input type="password" class="form-control" placeholder="密码" required="" th:field="*{user_passwd}" >
        <div class="checkbox mb-3">
            <label>
                <input type="checkbox" value="remember-me" th:text="记住我">
            </label>
        </div>
        <button class="btn btn-lg btn-primary btn-block" type="submit">登录</button>
        <p class="mt-5 mb-3 text-muted">© 2017-2018</p>
        <!--Thymeleaf参数传递,使用括号()-->
        <a class="btn btn-sm">中文</a>
        <a class="btn btn-sm">English</a>
    </form>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
2.主页面 index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>万象母婴店务营销管理系统 主页</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body class="text-center">
<div class="header-main">
    <div id="head" th:include="head.html :: common_head"></div>
</div>
    <br>
    <br>
    <h1>
        主页
    </h1>
    当前登录用户为<div th:text="${user.user_name}"></div>
    当前登录用户的角色为<div th:text="${user.user_ismanager==0?'用户':'管理员'}">"></div>
    <a class="btn btn-sm btn-success" href="#" th:href="@{/selectUser}"/>管理用户
    <a class="btn btn-sm btn-success" href="#" th:href="@{/selectGoods}"/>管理商品
    <a class="btn btn-sm btn-success" href="#" th:href="@{/selectOrder}"/>管理订单
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
3.登录失败页面 error.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录失败</title>
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body class="text-center">
<label>登录失败了!点击重新回到登录界面!</label>

    <a class="btn btn-danger" href="#" th:href="@{/toLogin}"/>回到登录页面

</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
4.操作失败页面 errordata.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>操作失败</title>
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body class="text-center">
<label>对数据的操作失败了!点击重新回到主界面!</label>

<a class="btn btn-danger" href="#" th:href="@{/}toIndex"/>回到主页面

</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
5.头导航条页面 head.html
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>登录</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
    <footer th:fragment="common_head">
        <!-----------------------------------------导航条设计开始--------------------------------->
        <!--黑色导航条样式为navbar-inverse,白色样式为default  , .navbar-fixed-top导航条固定在顶端-->
        <nav class="navbar navbar-inverse navbar-fixed-top">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <!------button为实现响应式布局,如果在手机上查看,点击button就可以弹出菜单---->
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#" th:href="@{/toLogin}" >万象母婴店务营销管理系统</a><!---放log的地方-->
                </div>

                <!-- 当浏览器小于某个值时,点击button图标显示导航条的内容(注意这里的id与button 的id对应)—>

               <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                   <! 具体菜单项-->
                <ul class="nav navbar-nav">
<!--                    <li class="active"><a href="#" th:href="@{/checkUser}">首页 <span class="sr-only">(current)</span></a></li>&lt;!&ndash;普通菜单&ndash;&gt;-->
                    <li class="dropdown"><!--下拉菜单-->
                        <a class="dropdown-toggle" href="#" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                            用户
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu dropdowncolor" aria-labelledby="dropdownMenu1">
                            <li><a href="#" th:href="@{/selectUser}">用户列表</a></li><!--下拉菜单项-->
                            <li><a href="#" th:href="@{/toAddPage}">添加用户</a></li>
                        </ul>
                    </li>
                    <li class="dropdown"><!--下拉菜单-->
                        <a class="dropdown-toggle" href="#" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                            订单
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu dropdowncolor" aria-labelledby="dropdownMenu1">
                            <li><a href="#" th:href="@{/selectOrder}">订单列表</a></li><!--下拉菜单项-->
                            <li><a href="#" th:href="@{/toAddOrderPage}">添加订单</a></li>
                        </ul>
                    </li>
                    <li class="dropdown"><!--下拉菜单-->
                        <a class="dropdown-toggle" href="#" id="dropdownMenu3" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                            商品
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu dropdowncolor" aria-labelledby="dropdownMenu1">
                            <li><a href="#" th:href="@{/selectGoods}">商品列表</a></li><!--下拉菜单项-->
                            <li><a href="#" th:href="@{/toAddGoodsPage}">添加商品</a></li>
                        </ul>
                    </li>
                </ul>

                <!--导航栏右部,一般的登录 注册-->
                <ul class="nav navbar-nav navbar-right">
<!--                    <li style="color: aliceblue">当前登录用户为:<div style="color: aliceblue" th:text="${user.user_name}"></div></li>-->
<!--                    <li style="color: aliceblue">当前登录用户的角色为:<div style="color: aliceblue" th:text="${user.user_ismanager==0?'用户':'管理员'}">"></div></li>-->
                    <li><a href="#" th:href="@{/toLogin}">登录</a></li>
                    <li><a href="#" th:href="@{/toAddPage}">注册</a></li>
                </ul>
            </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </nav>
        <!------------------------------------------导航条结束-------------------------------->
    </footer>
</head>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
6.用户
1.用户显示页面 user.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>查看用户</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <div class="header-main">
                <div id="head" th:include="head.html :: common_head"></div>
            </div>
            <br>
            <br>
            <h1>
                查看用户
            </h1>
            <h2>
                <a class="btn btn-sm btn-success" th:href="@{/toAddPage/}">添加用户</a>
                <a class="btn btn-sm btn-danger" th:href="@{/checkUser}">返回首页</a>
            </h2>
            <div class="table-responsive">
                <table class="table table-striped table-sm">
                    <thead>
                    <tr>
                        <th>用户ID</th>
                        <th>用户名</th>
                        <th>用户密码</th>
                        <th>是否是管理员</th>
                        <!--操作-->
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="user:${users}">
                        <td th:text="${user.user_id}"></td>
                        <td th:text="${user.user_name}"></td>
                        <td th:text="${user.user_passwd}"></td>
                        <!--性别,0为女,1为男-->
                        <td th:text="${user.user_ismanager==0?'':''}"></td>
                        <td>
                            <!--操作-->
                            <!--URL需要使用@-->
                            <a class="btn-sm btn-primary" th:href="@{/toUpdatePage/}+${user.user_id}">编辑</a>
                            <a class="btn-sm btn-danger" th:href="@{/deleteUser/}+${user.user_id}">删除</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </main>
    </div>
</div>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
2.用户添加页面 adduser.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body>
<div class="header-main">
    <div id="head" th:include="head.html :: common_head"></div>
</div>
<br>
<br>
<h1>
    新增用户
</h1>
<div class="container-fluid">
    <div class="row">
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <h2>
                <a class="btn btn-sm btn-success" th:href="@{/selectUser}">返回用户页面</a>
            </h2>
            <!--新增员工的表单-->
            <form th:action="@{/addUser}">
                <div class="form-group">
                    <label>用户名</label>
                    <input type="text"  name="user_name" class="form-control" placeholder="用户名字">
                </div>
                <div class="form-group">
                    <label>用户密码</label>
                    <input type="password" name="user_passwd" class="form-control" placeholder="用户密码">
                </div>
                <div class="form-group">
                    <label>是否是管理员</label><br/>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" type="radio" name="user_ismanager"  value="1">
                        <label class="form-check-label"></label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" type="radio" name="user_ismanager"  value="0">
                        <label class="form-check-label"></label>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary">添加</button>
            </form>
        </main>
    </div>
</div>
</form>
</body>
</html>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
3.用户修改页面 updateuser.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改用户</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <!--侧边栏-->
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <div class="header-main">
                <div id="head" th:include="head.html :: common_head"></div>
            </div>
            <br>
            <br>
            <h2>修改用户信息</h2>
            <!--修改员工的表单-->
            <label>要修改的用户ID</label><div th:text="${updateuser.user_id}"></div>
            <form th:action="@{/updateUser}" method="post">
                <!--隐藏域,保存要修改员工的id-->
                <div class="form-group">
                    <label>用户名</label>
                    <input type="hidden" name="user_id" th:value="${updateuser.user_id}">
                    <input type="text"  name="user_name" class="form-control" placeholder="用户名"
                           th:value="${updateuser.user_name}">
                </div>
                <div class="form-group">
                    <label>用户密码</label>
                    <input type="text" name="user_passwd" class="form-control" placeholder="用户密码"
                           th:value="${updateuser.user_passwd}">
                </div>
                <div class="form-group">
                    <label>是否是管理员</label><br/>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" type="radio" name="user_ismanager"  value="1"
                               th:checked="${updateuser.user_ismanager==1}">
                        <label class="form-check-label"></label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" type="radio" name="user_ismanager"  value="0"
                               th:checked="${updateuser.user_ismanager==0}">
                        <label class="form-check-label"></label>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary">修改</button>
            </form>
        </main>
    </div>
</div>

</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
7.订单
1.订单显示页面 order.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>查看订单</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <div class="header-main">
                <div id="head" th:include="head.html :: common_head"></div>
            </div>
            <br>
            <br>
            <h1>
                查看订单
            </h1>
            <h2>
                <a class="btn btn-sm btn-success" th:href="@{/toAddOrderPage}">添加订单</a>
                <a class="btn btn-sm btn-danger" th:href="@{/checkUser}">返回首页</a>
            </h2>
            <div class="table-responsive">
                <table class="table table-striped table-sm">
                    <thead>
                    <tr>
                        <th>订单ID</th>
                        <th>订单名</th>
                        <th>订单日期</th>
                        <th>订单所属用户</th>
                        <!--操作-->
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="orders:${orders}">
                        <td th:text="${orders.order_id}"></td>
                        <td th:text="${orders.order_name}"></td>
                        <td th:text="${orders.order_date}"></td>
                        <td th:text="${orders.order_userid}"></td>
                        <td>
                            <!--操作-->
                            <!--URL需要使用@-->
                            <a class="btn-sm btn-primary" th:href="@{/toUpdateOrderPage/}+${orders.order_id}">编辑</a>
                            <a class="btn-sm btn-danger" th:href="@{/deleteOrder/}+${orders.order_id}">删除</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </main>
    </div>
</div>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
2.订单添加页面 addorder.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加订单</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body>
<div class="header-main">
    <div id="head" th:include="head.html :: common_head"></div>
</div>
<br>
<br>
<h1>
    新增订单
</h1>
<div class="container-fluid">
    <div class="row">
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <h2>
                <a class="btn btn-sm btn-success" th:href="@{/selectOrder}">返回订单页面</a>
            </h2>
            <!--新增订单的表单-->
            <form th:action="@{/addOrder}">
                <div class="form-group">
                    <label>订单名</label>
                    <input type="text"  name="order_name" class="form-control" placeholder="订单名字">
                </div>
                <div class="form-group">
                    <label>订单日期</label>
                    <input type="date" name="order_date" class="form-control" placeholder="订单日期">
                </div>
                <div class="form-group">
                    <label>订单用户</label>
                    <select class="form-control" name="order_userid">
                        <option th:each="user:${ordersuser}"
                                th:text="${user.user_name}" th:value="${user.user_id}"></option>
                    </select>
                </div>
                <button type="submit" class="btn btn-primary">添加</button>
            </form>
        </main>
    </div>
</div>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
3.订单修改页面 updateorder.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改订单</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <!--侧边栏-->
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <div class="header-main">
                <div id="head" th:include="head.html :: common_head"></div>
            </div>
            <br>
            <br>
            <h2>修改订单信息</h2>
            <!--修改订单的表单-->
            <label>要修改的订单ID</label><div th:text="${updateorder.order_id}"></div>
            <form th:action="@{/updateOrder}" method="post">
                <!--隐藏域,保存要修改员工的id-->
                <div class="form-group">
                    <label>订单名称</label>
                    <input type="hidden" name="order_id" th:value="${updateorder.order_id}">
                    <input type="text"  name="order_name" class="form-control" placeholder="订单名"
                           th:value="${updateorder.order_name}">
                </div>
                <div class="form-group">
                    <label>订单日期</label>
                    <input type="date" name="order_date" class="form-control" placeholder="订单日期"
                           th:value="${updateorder.order_date}">
                </div>
                <div class="form-group">
                    <label>订单用户</label>
                    <select class="form-control" name="order_userid">
                        <option th:each="user:${ordersuser}"
                                th:text="${user.user_name}" th:value="${user.user_id}"></option>
                    </select>
                </div>
                <button type="submit" class="btn btn-primary">修改</button>
            </form>
        </main>
    </div>
</div>

</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
8.商品
1.商品显示页面 goods.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>查看商品</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <div class="header-main">
                <div id="head" th:include="head.html :: common_head"></div>
            </div>
            <br>
            <br>
            <h1>
                查看商品
            </h1>
            <h2>
                <a class="btn btn-sm btn-success" th:href="@{/toAddGoodsPage}">添加商品</a>
                <a class="btn btn-sm btn-danger" th:href="@{/checkUser}">返回首页</a>
            </h2>
            <div class="table-responsive">
                <table class="table table-striped table-sm">
                    <thead>
                    <tr>
                        <th>商品ID</th>
                        <th>商品名</th>
                        <th>商品描述</th>
                        <th>商品数量</th>
                        <th>商品所属订单ID</th>
                        <!--操作-->
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="good:${goods}">
                        <td th:text="${good.goods_id}"></td>
                        <td th:text="${good.goods_name}"></td>
                        <td th:text="${good.goods_description}"></td>
                        <td th:text="${good.goods_count}"></td>
                        <td th:text="${good.goods_orderid}"></td>
                        <td>
                            <!--操作-->
                            <!--URL需要使用@-->
                            <a class="btn-sm btn-primary" th:href="@{/toUpdateGoodsPage/}+${good.goods_id}">编辑</a>
                            <a class="btn-sm btn-danger" th:href="@{/deleteGoods/}+${good.goods_id}">删除</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </main>
    </div>
</div>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
2.商品添加页面 addgoods.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加商品</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body>
<div class="header-main">
    <div id="head" th:include="head.html :: common_head"></div>
</div>
<br>
<br>
<h1>
    新增商品
</h1>
<div class="container-fluid">
    <div class="row">
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <h2>
                <a class="btn btn-sm btn-success" th:href="@{/selectGoods}">返回商品页面</a>
            </h2>
            <!--新增商品的表单-->
            <form th:action="@{/addGoods}">
                <div class="form-group">
                    <label>商品名</label>
                    <input type="text"  name="goods_name" class="form-control" placeholder="商品名称">
                </div>
                <div class="form-group">
                    <label>商品描述</label>
                    <input type="text" name="goods_description" class="form-control" placeholder="商品描述">
                </div>
                <div class="form-group">
                    <label>商品数量</label>
                    <input type="text" name="goods_count" class="form-control" placeholder="商品数量">
                </div>
                <div class="form-group">
                    <label>商品属于订单</label>
                    <select class="form-control" name="goods_orderid">
                        <option th:each="order:${ordergoods}"
                                th:text="${order.order_name}" th:value="${order.order_id}"></option>
                    </select>
                </div>
                <button type="submit" class="btn btn-primary">添加</button>
            </form>
        </main>
    </div>
</div>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
3.商品修改页面 updategoods.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改商品</title>
    <!-- 引入JQuery -->
    <script src="js/jquery-3.4.1.min.js" th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <!-- 引入BootStrap-->
    <link href="css/bootstrap/css/bootstrap.min.css" th:href="@{/css/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
    <script src="css/bootstrap/js/bootstrap.min.js" th:src="@{/css/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <!--侧边栏-->
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <div class="header-main">
                <div id="head" th:include="head.html :: common_head"></div>
            </div>
            <br>
            <br>
            <h2>修改商品信息</h2>
            <!--修改商品的表单-->
            <label>要修改的商品ID</label><div th:text="${updategoods.goods_id}"></div>
            <form th:action="@{/updateGoods}" method="post">
                <!--隐藏域,保存要修改商品的id-->
                <div class="form-group">
                    <label>商品名称</label>
                    <input type="hidden" name="goods_id" th:value="${updategoods.goods_id}">
                    <input type="text"  name="goods_name" class="form-control" placeholder="商品名称"
                           th:value="${updategoods.goods_name}">
                </div>
                <div class="form-group">
                    <label>商品描述</label>
                    <input type="text" name="goods_description" class="form-control" placeholder="商品描述"
                           th:value="${updategoods.goods_description}">
                </div>
                <div class="form-group">
                    <label>商品数量</label>
                    <input type="text" name="goods_count" class="form-control" placeholder="商品数量"
                           th:value="${updategoods.goods_count}">
                </div>
                <div class="form-group">
                    <label>商品订单</label>
                    <select class="form-control" name="goods_orderid">
                        <option th:each="order:${ordergoods}"
                                th:text="${order.order_name}" th:value="${order.order_id}"></option>
                    </select>
                </div>
                <button type="submit" class="btn btn-primary">修改</button>
            </form>
        </main>
    </div>
</div>

</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57

概览

当你完成了以上所有代码的编写后,当前代码结构应该如图所示:
在这里插入图片描述

运行

配置好Tomcat运行环境后,运行启动类,即可开始运行,结果图如下:

  1. 调用/toLogin请求,访问登录页面,如图所示:
    在这里插入图片描述
  2. 输入错误账号密码,会调用/checkUser请求判断账号密码是否匹配,匹配不上则弹出错误页面,如图所示:
    在这里插入图片描述
  3. 输入正确账号密码,进入主页,如图所示:
    在这里插入图片描述
  4. 进入用户列表,可以查看用户的信息,并且进行相应的操作,如图所示:
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

后记

耽搁了一个月才开始更新博客,属实是最近有些懒惰了,实在抱歉。近期也在准备春招的事情,待我整理完后,将会把春招的面经更新到博客上。
相比于SSM,Spring Boot的明显优点在于配置文件的简化,以及可以使用独特的Thymeleaf模板引擎来支持使用html代码,通过restful调用,就可以快速而高效地搭建出一个Web项目。当然,编程的思想才应该是我们注重的关键,有了编程的思想,无论使用什么框架都能够很快地了解其思想,并且进行正确地调用。
如果读者在浏览该博客时遇到什么问题,可以及时联系我,或者在留言区留下问题,我在看到后会第一时间回复,感谢您的浏览!
另附源码地址: Spring Boot版本 简易管理系统

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/860064
推荐阅读
相关标签
  

闽ICP备14008679号