JWT(鉴权)_学生管理系统
文章目录
- 需要实现的功能:
- 整个项目架构
- 创建数据库表
- 创建整个工程父项目
- 创建pojo项目
- 创建工具项目
- 创建Eureka项目
- 创建zuul(网关)项目
- 创建JWT鉴权项目
- 老师账号登录,采用JWT进行认证+授权
- 创建老师项目
- 创建班级项目
- 班级新增
- 班级修改
- 单个班级删除(假删)
- 查询所有班级
- 创建学生项目
- 学生新增
- 学生批量删除
- 多条件组合查询
需要实现的功能:
老师登录之后,可以对老师类型、老师信息、班级、学生信息进行管理。
1、老师账号登录,采用JWT进行认证+授权
2、班级管理
- 班级新增(默认不删除状态,也就是is_delete的默认值是0)
- 班级修改
- 单个班级删除(假删除,修改is_delete字段)
- 查询所有班级(基本功能+老师信息+5分创建的老师信息共)
3、学生管理
- 学生新增
- 学生批量删除(在地址栏传递多个id过去)
- 学生分页多条件组合查询(名字模糊查询+年龄范围查询+性别+班级)
整个项目架构
整个项目运行
创建数据库表
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for classes
-- ----------------------------
DROP TABLE IF EXISTS `classes`;
CREATE TABLE `classes` (`id` int(11) NOT NULL AUTO_INCREMENT,`classname` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,`tea_id` int(11) NULL DEFAULT NULL COMMENT '辅导员id',`create_id` int(11) NULL DEFAULT NULL,`is_delete` int(255) NULL DEFAULT NULL COMMENT '是否删除0未删除1已删除',PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 22 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;-- ----------------------------
-- Records of classes
-- ----------------------------
INSERT INTO `classes` VALUES (1, 'JAVA1班NB', 1, 1, 0);
INSERT INTO `classes` VALUES (2, 'JAVA2班', 1, 2, 0);
INSERT INTO `classes` VALUES (3, 'JAVA3班NB', 2, 3, 0);
INSERT INTO `classes` VALUES (4, 'JAVA4班NBB', 2, 4, 0);
INSERT INTO `classes` VALUES (5, 'Python1班', 2, 5, 0);
INSERT INTO `classes` VALUES (6, 'Python2班', 3, 6, 0);
INSERT INTO `classes` VALUES (7, '全栈1班', 3, 1, 0);
INSERT INTO `classes` VALUES (8, '全栈2班', 3, 1, 0);-- ----------------------------
-- Table structure for student
-- ----------------------------
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (`stuid` int(11) NOT NULL AUTO_INCREMENT,`stuname` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,`age` int(11) NULL DEFAULT NULL,`sex` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,`classid` int(11) NOT NULL,`birthday` date NULL DEFAULT NULL,`create_id` int(50) NULL DEFAULT NULL,PRIMARY KEY (`stuid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;-- ----------------------------
-- Records of student
-- ----------------------------
INSERT INTO `student` VALUES (1, '张三', 18, '男', 1, '2000-02-01', 1);
INSERT INTO `student` VALUES (2, '李四', 18, '男', 1, '2000-02-09', 1);
INSERT INTO `student` VALUES (3, '王二', 21, '男', 1, '1997-07-26', 2);
INSERT INTO `student` VALUES (4, 'tom', 19, '女', 2, '1999-01-02', 2);
INSERT INTO `student` VALUES (5, 'lucy', 19, '女', 2, '1999-05-23', 3);
INSERT INTO `student` VALUES (6, 'jack', 20, '男', 2, '1999-11-15', 3);
INSERT INTO `student` VALUES (7, 'tony', 20, '男', 3, '1999-10-01', 4);
INSERT INTO `student` VALUES (8, 'rose', 21, '女', 4, '1999-08-07', 5);-- ----------------------------
-- Table structure for teacher
-- ----------------------------
DROP TABLE IF EXISTS `teacher`;
CREATE TABLE `teacher` (`tea_id` int(11) NOT NULL AUTO_INCREMENT,`tea_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,`type_id` int(11) NULL DEFAULT NULL,PRIMARY KEY (`tea_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;-- ----------------------------
-- Records of teacher
-- ----------------------------
INSERT INTO `teacher` VALUES (1, '谢锋', '123', 1);
INSERT INTO `teacher` VALUES (2, '刘华', '123', 2);
INSERT INTO `teacher` VALUES (3, '齐秦', '123', 3);
INSERT INTO `teacher` VALUES (4, '张妹', '123', 4);-- ----------------------------
-- Table structure for type
-- ----------------------------
DROP TABLE IF EXISTS `type`;
CREATE TABLE `type` (`type_id` int(11) NOT NULL,`type_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,PRIMARY KEY (`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;-- ----------------------------
-- Records of type
-- ----------------------------
INSERT INTO `type` VALUES (1, '讲师');
INSERT INTO `type` VALUES (2, '助教');
INSERT INTO `type` VALUES (3, '辅导员');
INSERT INTO `type` VALUES (4, '财务老师');
INSERT INTO `type` VALUES (5, '院办老师');
INSERT INTO `type` VALUES (6, '后勤老师');SET FOREIGN_KEY_CHECKS = 1;
创建整个工程父项目
- 把src目录删除掉
- 导入pom文件 (父工程就创建完毕)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=".0.0" xmlns:xsi=""xsi:schemaLocation=".0.0 .0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.czxy</groupId><artifactId>stu-parent1964</artifactId><version>0.0.1-SNAPSHOT</version><name>stu-parent1964</name><description>Demo project for Spring Boot</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.2.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><modules><module>stu-pojo1964</module><module>stu-common1964</module></modules><!-- 父工程中只是统一版本依赖,但是不实际导入jar包 --><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>Hoxton.RELEASE</spring-cloud.version><mybatis.starter.version>1.3.2</mybatis.starter.version><mapper.starter.version>2.0.2</mapper.starter.version><druid.starter.version>1.1.9</druid.starter.version><mysql.version>5.1.32</mysql.version><pageHelper.starter.version>1.2.3</pageHelper.starter.version><jjwt.version>0.7.0</jjwt.version><joda-time.version>2.9.6</joda-time.version><lombok.version>1.18.10</lombok.version></properties><!-- dependencyManagement这个标签一般用在父项目中,他不是导入jar包的标签,只是用来限定jar包版本的标签然后子项目依赖当前父项目,在子项目中导入需要的jar包坐标子项目无需填入版本号,完全由父项目控制--><dependencyManagement><dependencies><!-- springCloud --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><!-- mybatis启动器 --><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>${mybatis.starter.version}</version></dependency><!-- 通用Mapper启动器 --><dependency><groupId>tk.mybatis</groupId><artifactId>mapper-spring-boot-starter</artifactId><version>${mapper.starter.version}</version></dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>${pageHelper.starter.version}</version></dependency><!-- druid启动器 --><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>${druid.starter.version}</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>${mysql.version}</version></dependency><dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt</artifactId><version>${jjwt.version}</version></dependency><!-- --><dependency><groupId>joda-time</groupId><artifactId>joda-time</artifactId><version>${joda-time.version}</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></dependency></dependencies></dependencyManagement><!-- 配置Spring私服: 提高下载速度--><repositories><repository><id>spring-milestones</id><name>Spring Milestones</name><url>;/url><snapshots><enabled>false</enabled></snapshots></repository></repositories><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>
创建pojo项目
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=".0.0" xmlns:xsi=""xsi:schemaLocation=".0.0 .0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId
发布评论