1. 设计思路
1.1 技术栈选择
后端:shiro + springboot + springMVC + mybatis + druid + mysql
前端:thymeleaf + bootstrap
1.2 数据建模
用户信息
字段 | 数据类型 | 字段描述 | 字段长度 | 是否主键 | 是否为空 |
---|---|---|---|---|---|
id | int | ID | - | √ | |
name | varchar | 用户名 | 20 | ||
rbac | tinyint | 是否为管理员 | 1 | ||
pwd | varchar | 密码 | 20 |
物料信息
字段 | 数据类型 | 字段描述 | 字段长度 | 是否主键 | 是否为空 |
---|---|---|---|---|---|
art_no | int | 货号 | - | √ | |
name | varchar | 货物名称 | 20 | ||
avg_price | decimal | 总仓均价 | 10, 5 | ||
amount | int | 数量 | - |
台账
字段 | 数据类型 | 字段描述 | 字段长度 | 是否主键 | 是否为空 |
---|---|---|---|---|---|
time_stamp | timestamp | 记录时间 | 6 | √ | |
depo_no | varchar | 所属仓库 | 10 | √ | |
art_no | int | 货号 | - | ||
state | tinyint | 出库/入库 | 1 | ||
amount | int | 数量()标准单位 | - | ||
unit_price | decimal | 单价 | 10, 5 | ||
total | decimal | 总金额 | 10, 5 | ||
target | varchar | 来源/去向 | 20 |
货物信息
字段 | 数据类型 | 字段描述 | 字段长度 | 是否主键 | 是否为空 |
---|---|---|---|---|---|
art_no | int | 货号 | - | √ | |
depo_no | varchar | 所属仓库 | 10 | √ | |
amount | int | 数量 | - | ||
unit_price | decimal | 单价 | 10, 5 |
1.3 框架搭建
直接改的上学期的仓库管理系统,因为正好用thymeleaf重构了前端,所以就不实现接口了(其实是纯纯的不会
项目整体目录结构如图
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.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hoppi</groupId>
<artifactId>SpringBootDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringBootDemo</name>
<description>SpringBootDemo</description>
<properties>
<java.version>18</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.webjars/jquery -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.6.0</version>
</dependency>
<!-- thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.2</version>
</dependency>
<!-- shiro -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
application.yaml
spring:
browser:
open: true
url: http://localhost:8080
datasource:
username: root
password: ******
url: jdbc:mysql://localhost:3306/depo_db?userSSL=true&useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
filters: stat, wall, logback
maxPoolPreparedStatementPerConnectionSize: 20
useGlobalDataSourceStat: true
connectionProperties: druid.stat.mergeSql=true; druid.stat.slowSqlMillis=500
thymeleaf:
cache: false
mybatis:
type-aliases-package: com.hoppi.pojo
mapper-locations: classpath:mybatis/mapper/*.xml
数据库脚本(不含数据,并且因为我没有写注册功能,只能自己在数据库里创建第一个管理员以登录和创建更多用户)
CREATE DATABASE `depo_db`CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `depo_db`;
CREATE TABLE `depository` (
`art_no` int NOT NULL,
`amount` int NOT NULL,
`unit_price` decimal(10,5) NOT NULL COMMENT '单价',
`depo_no` varchar(10) NOT NULL COMMENT '所属仓库',
PRIMARY KEY (`art_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `log` (
`time_stamp` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`depo_no` varchar(10) NOT NULL,
`art_no` int NOT NULL,
`state` tinyint(1) NOT NULL COMMENT '入库为1,出库为0',
`amount` int NOT NULL,
`unit_price` decimal(10,5) NOT NULL COMMENT '单价',
`total` decimal(10,5) NOT NULL COMMENT '总金额',
`target` varchar(20) NOT NULL COMMENT '去向/来源',
PRIMARY KEY (`time_stamp`,`depo_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `stuff` (
`art_no` int NOT NULL,
`name` varchar(20) NOT NULL,
`avg_price` decimal(10,5) NOT NULL,
PRIMARY KEY (`art_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `user` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`rbac` tinyint(1) NOT NULL DEFAULT '0' COMMENT '权限控制',
`pwd` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2. 图文展示
2.1 架构图
2.2 数据建模ER图
2.3 基本数据流图
3. 遇到的问题以及解决办法
遇到的问题都是前端的( ╯□╰ )
问题1:
原先的Spring项目中使用的模板引擎是JSP
重构成SpringBoot项目时转换成Thymeleaf,导致大量JSP语法片段失效
解决方法: 重写
问题2:
JS似乎无法清除Thymeleaf的session(反正我没找到方法),导致关闭弹窗后刷新页面仍然出现弹窗的离谱情况
解决方法: 本来想用Thymeleaf的语法调用Java方法清除session,但没找到相关文章,所以选择了转发+JS延时自动跳转的方式,缺陷是弹窗要加一句“三秒后自动关闭”
4. 我的收获
学会了使用SpringBoot(入门级)
第一次画架构图(
水了一篇博客(bushi)