learn02
This commit is contained in:
parent
3f8d7e5fc5
commit
058dea58cb
@ -20,7 +20,7 @@
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<processorPath useClasspath="false">
|
||||
<processorPath>
|
||||
<entry name="D:/software/dev/maven/apache-maven-3.9.9/repository/org/projectlombok/lombok/release/lombok-release.jar" />
|
||||
</processorPath>
|
||||
<module name="learn03-springboot" />
|
||||
|
||||
@ -77,6 +77,12 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>0.12.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -2,7 +2,9 @@ package test05;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
|
||||
@ServletComponentScan
|
||||
@SpringBootApplication
|
||||
public class Test05Application {
|
||||
|
||||
|
||||
36
test05/src/main/java/test05/controller/LoginController.java
Normal file
36
test05/src/main/java/test05/controller/LoginController.java
Normal file
@ -0,0 +1,36 @@
|
||||
package test05.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import test05.pojo.Result;
|
||||
import test05.pojo.User;
|
||||
import test05.service.UserService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/userAction")
|
||||
public class LoginController {
|
||||
private final UserService userService;
|
||||
@Autowired
|
||||
public LoginController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping("/login")
|
||||
public Result login(String username, String password, HttpSession session) {
|
||||
if (session.getAttribute("user") != null) {
|
||||
return Result.success(session.getAttribute("user"));
|
||||
}else if (username==null || password==null) {
|
||||
return Result.error("login fail");
|
||||
}
|
||||
Result res = userService.login(new User(username, password));
|
||||
if (res.isSuccess()) {
|
||||
session.setAttribute("user", res.getData());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
20
test05/src/main/java/test05/filter/loginFilter.java
Normal file
20
test05/src/main/java/test05/filter/loginFilter.java
Normal file
@ -0,0 +1,20 @@
|
||||
package test05.filter;
|
||||
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.annotation.WebFilter;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
@WebFilter("/*Action/*")
|
||||
public class loginFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
if (Objects.equals(((HttpServletRequest) servletRequest).getRequestURI(), "/userAction/login")) {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,7 @@ import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
List<User> selectUser(User user);
|
||||
List<User> selectUser(User user, int page, int pageSize);
|
||||
User selectUserByName(String username);
|
||||
int insertUser(User user);
|
||||
int deleteUser(User user);
|
||||
|
||||
@ -10,20 +10,20 @@ import lombok.NonNull;
|
||||
@NoArgsConstructor
|
||||
public class Student {
|
||||
@NonNull
|
||||
private Integer N_STUDENT_ID=-1;
|
||||
private Integer id =-1;
|
||||
@NonNull
|
||||
private String VC_STUDENT_CODE="";
|
||||
private String code ="";
|
||||
@NonNull
|
||||
private String VC_STUDENT_NAME="";
|
||||
private String name ="";
|
||||
@NonNull
|
||||
private Integer N_SEX=-1;
|
||||
private Integer sex =-1;
|
||||
@NonNull
|
||||
private Integer N_GRADE=-1;
|
||||
private Integer grade =-1;
|
||||
@NonNull
|
||||
private Integer N_MAJOR=-1;
|
||||
private Integer major =-1;
|
||||
@NonNull
|
||||
private String VC_DETAIL="";
|
||||
private String detail ="";
|
||||
public Student(int id){
|
||||
N_STUDENT_ID=id;
|
||||
this.id =id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,12 +10,16 @@ import lombok.NonNull;
|
||||
@NoArgsConstructor
|
||||
public class User {
|
||||
@NonNull
|
||||
private Integer N_USER_ID=-1;
|
||||
private Integer id =-1;
|
||||
@NonNull
|
||||
private String VC_LOGIN_NAME ="";
|
||||
private String name ="";
|
||||
@NonNull
|
||||
private String VC_PASSWORD="";
|
||||
private String password ="";
|
||||
public User(int id){
|
||||
N_USER_ID = id;
|
||||
this.id = id;
|
||||
}
|
||||
public User(@NonNull String name, @NonNull String password){
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,13 @@
|
||||
package test05.service;
|
||||
|
||||
import test05.pojo.Result;
|
||||
import test05.pojo.User;
|
||||
|
||||
public interface UserService {
|
||||
/**
|
||||
* 用户登录服务
|
||||
* @param user 包含用户名和密码用于比对
|
||||
* @return 登录结果
|
||||
*/
|
||||
public Result login(User user);
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ public class CourseServiceImpl implements CourseService {
|
||||
return "do not set N_COURSE_ID";
|
||||
}
|
||||
if (course.getName().length()<4||course.getName().length()>25){
|
||||
return "name too long";
|
||||
return "name invalid";
|
||||
}
|
||||
if (course.getGrade()>3000||course.getGrade()<2000){
|
||||
return "grade invalid";
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package test05.service.impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import test05.mapper.UserMapper;
|
||||
import test05.pojo.Result;
|
||||
import test05.pojo.User;
|
||||
import test05.service.UserService;
|
||||
import test05.utils.JwtUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
private UserMapper userMapper;
|
||||
@Autowired
|
||||
public void setUserMapper(UserMapper userMapper) {
|
||||
this.userMapper = userMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result login(User user) {
|
||||
User selectUser = userMapper.selectUserByName(user.getName());
|
||||
if (selectUser == null) {
|
||||
return Result.error("user dose not exist");
|
||||
}
|
||||
if (selectUser.getPassword().equals(user.getPassword())) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("id", selectUser.getId());
|
||||
map.put("name", selectUser.getName());
|
||||
return Result.success(JwtUtils.getJwt(map));
|
||||
}else{
|
||||
return Result.error("password incorrect");
|
||||
}
|
||||
}
|
||||
}
|
||||
53
test05/src/main/java/test05/utils/JwtUtils.java
Normal file
53
test05/src/main/java/test05/utils/JwtUtils.java
Normal file
@ -0,0 +1,53 @@
|
||||
package test05.utils;
|
||||
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JwtUtils {
|
||||
static private final SecretKey KEY=Keys.hmacShaKeyFor("12@529#5e2#54t8r8$0454g9&hj|03nb13df1h1351xY".getBytes());
|
||||
// ms s m h d
|
||||
static private final int[] expireTime = {0,0,0,3,0};
|
||||
|
||||
static public String getJwt(Map<String, Object> map){
|
||||
return Jwts.builder()
|
||||
// 设置头部信息header
|
||||
.header()
|
||||
.add("typ", "JWT")
|
||||
.add("alg", "HS256")
|
||||
.and()
|
||||
// 设置自定义负载信息payload
|
||||
.claim("data", map)
|
||||
// 过期日期
|
||||
.expiration(getExpireTime())
|
||||
// 签名8
|
||||
.signWith(KEY)
|
||||
.compact();
|
||||
}
|
||||
static public void setExpireTime(int ms, int seconds, int minutes, int hour,int day){
|
||||
expireTime[0] = ms;
|
||||
expireTime[1] = seconds;
|
||||
expireTime[2] = minutes;
|
||||
expireTime[3] = hour;
|
||||
expireTime[4] = day;
|
||||
}
|
||||
static public Date getExpireTime(){
|
||||
return new Date(System.currentTimeMillis()
|
||||
+ (expireTime[0])
|
||||
+ (expireTime[1] * 1000L)
|
||||
+ (expireTime[2] * 60000L)
|
||||
+ (expireTime[3] * 3600000L)
|
||||
+ (expireTime[4] * 86400000L)
|
||||
);
|
||||
}
|
||||
static public Map<String, Object> parseJwt(String jwt){
|
||||
return Jwts.parser()
|
||||
.verifyWith(KEY)
|
||||
.build()
|
||||
.parseSignedClaims(jwt).getPayload();
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,7 @@
|
||||
N_TYPE AS type,
|
||||
F_CREDIT AS credit,
|
||||
N_MAJOR AS major,
|
||||
N_GRADE AS grade,
|
||||
VC_DETAIL AS detail
|
||||
FROM t_course
|
||||
WHERE #{course.id} in (N_COURSE_ID, -1)
|
||||
@ -16,19 +17,19 @@
|
||||
AND #{course.credit} in (F_CREDIT, -1)
|
||||
AND #{course.major} in (N_MAJOR, -1)
|
||||
AND UPPER(VC_COURSE_NAME) LIKE CONCAT('%', UPPER(#{course.name}), '%')
|
||||
ORDER BY N_COURSE_ID
|
||||
LIMIT #{page}*#{pageSize},#{pageSize}
|
||||
ORDER BY N_COURSE_ID DESC
|
||||
LIMIT (#{page}-1)*#{pageSize},#{pageSize}
|
||||
</select>
|
||||
<select id="selectCourseCount" resultType="int">
|
||||
SELECT COUNT(*)
|
||||
FROM t_course
|
||||
WHERE #{N_COURSE_ID} in (N_COURSE_ID, -1)
|
||||
AND #{N_TYPE} in (N_TYPE, -1)
|
||||
AND #{F_CREDIT} in (F_CREDIT, -1)
|
||||
AND #{N_MAJOR} in (N_MAJOR, -1)
|
||||
AND UPPER(VC_COURSE_NAME) LIKE CONCAT('%', UPPER(#{VC_COURSE_NAME}), '%')
|
||||
WHERE #{id} in (N_COURSE_ID, -1)
|
||||
AND #{type} in (N_TYPE, -1)
|
||||
AND #{credit} in (F_CREDIT, -1)
|
||||
AND #{major} in (N_MAJOR, -1)
|
||||
AND UPPER(VC_COURSE_NAME) LIKE CONCAT('%', UPPER(#{name}), '%')
|
||||
</select>
|
||||
<insert id="insertCourse" keyProperty="N_COURSE_ID" useGeneratedKeys="true">
|
||||
<insert id="insertCourse" keyProperty="id" useGeneratedKeys="true">
|
||||
INSERT INTO t_course
|
||||
(VC_COURSE_NAME, N_TYPE, F_CREDIT, N_GRADE, N_MAJOR, VC_DETAIL)
|
||||
VALUES (#{name}, #{type}, #{credit}, #{grade}, #{major}, #{detail})
|
||||
|
||||
@ -4,37 +4,43 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="test05.mapper.StudentMapper">
|
||||
<select id="selectStudent" resultType="test05.pojo.Student">
|
||||
SELECT *
|
||||
SELECT N_STUDENT_ID AS id,
|
||||
VC_STUDENT_CODE AS code,
|
||||
VC_STUDENT_NAME AS name,
|
||||
N_SEX AS sex,
|
||||
N_MAJOR AS major,
|
||||
N_GRADE AS grade,
|
||||
VC_DETAIL AS detail
|
||||
FROM t_student
|
||||
WHERE #{student.N_STUDENT_ID} in (N_STUDENT_ID, -1)
|
||||
AND VC_STUDENT_CODE LIKE CONCAT('%', #{student.VC_STUDENT_CODE}, '%')
|
||||
AND VC_STUDENT_NAME LIKE CONCAT('%', #{student.VC_STUDENT_NAME}, '%')
|
||||
AND #{student.N_SEX} in (N_SEX, -1)
|
||||
AND #{student.N_GRADE} in (N_GRADE, -1)
|
||||
AND #{student.N_MAJOR} in (N_MAJOR, -1)
|
||||
AND VC_DETAIL LIKE CONCAT('%', #{student.VC_DETAIL}, '%')
|
||||
ORDER BY N_STUDENT_ID
|
||||
LIMIT #{page}*#{pageSize},#{pageSize}
|
||||
WHERE #{student.id} in (N_STUDENT_ID, -1)
|
||||
AND VC_STUDENT_CODE LIKE CONCAT('%', #{student.code}, '%')
|
||||
AND VC_STUDENT_NAME LIKE CONCAT('%', #{student.name}, '%')
|
||||
AND #{student.sex} in (N_SEX, -1)
|
||||
AND #{student.grade} in (N_GRADE, -1)
|
||||
AND #{student.major} in (N_MAJOR, -1)
|
||||
AND VC_DETAIL LIKE CONCAT('%', #{student.detail}, '%')
|
||||
ORDER BY N_STUDENT_ID DESC
|
||||
LIMIT (#{page}-1)*#{pageSize},#{pageSize}
|
||||
</select>
|
||||
<insert id="insertStudent" useGeneratedKeys="true" keyProperty="N_STUDENT_ID">
|
||||
<insert id="insertStudent" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO t_student
|
||||
(VC_STUDENT_CODE, VC_STUDENT_NAME, N_SEX, N_GRADE, N_MAJOR, VC_DETAIL)
|
||||
VALUES
|
||||
(#{VC_STUDENT_CODE},#{VC_STUDENT_NAME},#{N_SEX},#{N_GRADE},#{N_MAJOR},#{VC_DETAIL});
|
||||
(#{code},#{name},#{sex},#{grade},#{major},#{detail});
|
||||
</insert>
|
||||
<delete id="deleteStudent">
|
||||
DELETE
|
||||
FROM t_student
|
||||
WHERE N_STUDENT_ID = #{N_STUDENT_ID};
|
||||
WHERE N_STUDENT_ID = #{id};
|
||||
</delete>
|
||||
<update id="updateStudent">
|
||||
UPDATE t_student
|
||||
SET VC_STUDENT_CODE=#{VC_STUDENT_CODE},
|
||||
VC_STUDENT_NAME=#{VC_STUDENT_NAME},
|
||||
N_SEX=#{N_SEX},
|
||||
N_GRADE=#{N_GRADE},
|
||||
N_MAJOR=#{N_MAJOR},
|
||||
VC_DETAIL=#{VC_DETAIL}
|
||||
WHERE N_STUDENT_ID=#{N_STUDENT_ID};
|
||||
SET VC_STUDENT_CODE=#{code},
|
||||
VC_STUDENT_NAME=#{name},
|
||||
N_SEX=#{sex},
|
||||
N_GRADE=#{grade},
|
||||
N_MAJOR=#{major},
|
||||
VC_DETAIL=#{detail}
|
||||
WHERE N_STUDENT_ID=#{id};
|
||||
</update>
|
||||
</mapper>
|
||||
@ -4,32 +4,38 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="test05.mapper.UserMapper">
|
||||
<select id="selectUser" resultType="test05.pojo.User">
|
||||
SELECT *
|
||||
SELECT N_USER_ID AS id,
|
||||
VC_LOGIN_NAME AS name,
|
||||
VC_PASSWORD AS password
|
||||
FROM t_user
|
||||
WHERE
|
||||
#{N_USER_ID} IN (N_USER_ID, -1)
|
||||
AND VC_LOGIN_NAME LIKE CONCAT('%',#{VC_LOGIN_NAME},'%')
|
||||
AND VC_PASSWORD LIKE CONCAT('%',#{VC_PASSWORD},'%')
|
||||
#{user.id} IN (N_USER_ID, -1)
|
||||
AND VC_LOGIN_NAME LIKE CONCAT('%',#{user.name},'%')
|
||||
AND VC_PASSWORD LIKE CONCAT('%',#{user.password},'%')
|
||||
ORDER BY N_USER_ID DESC
|
||||
LIMIT (#{page}-1)*#{pageSize},#{pageSize}
|
||||
</select>
|
||||
<insert id="insertUser" useGeneratedKeys="true" keyProperty="N_USER_ID">
|
||||
<insert id="insertUser" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO t_user
|
||||
(VC_LOGIN_NAME, VC_PASSWORD)
|
||||
VALUES
|
||||
(#{VC_LOGIN_NAME}, #{VC_PASSWORD})
|
||||
(#{name}, #{password})
|
||||
</insert>
|
||||
<update id="updateUser">
|
||||
UPDATE t_user
|
||||
SET VC_PASSWORD=#{VC_PASSWORD},
|
||||
VC_LOGIN_NAME=#{VC_LOGIN_NAME}
|
||||
WHERE N_USER_ID = #{N_USER_ID};
|
||||
SET VC_PASSWORD=#{password},
|
||||
VC_LOGIN_NAME=#{name}
|
||||
WHERE N_USER_ID = #{id};
|
||||
</update>
|
||||
<delete id="deleteUser">
|
||||
DELETE
|
||||
FROM t_user
|
||||
WHERE N_USER_ID = #{N_USER_ID}
|
||||
WHERE N_USER_ID = #{id}
|
||||
</delete>
|
||||
<select id="selectUserByName" resultType="test05.pojo.User">
|
||||
SELECT *
|
||||
SELECT N_USER_ID AS id,
|
||||
VC_LOGIN_NAME AS name,
|
||||
VC_PASSWORD AS password
|
||||
FROM t_user
|
||||
WHERE VC_LOGIN_NAME = #{username};
|
||||
</select>
|
||||
|
||||
@ -1,13 +1,19 @@
|
||||
package test05;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jws;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.opentest4j.TestAbortedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import test05.mapper.*;
|
||||
import test05.pojo.*;
|
||||
import test05.utils.JwtUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
class Test05ApplicationTests {
|
||||
@ -23,7 +29,7 @@ class Test05ApplicationTests {
|
||||
UserMapper userMapper;
|
||||
|
||||
@Test
|
||||
public void courseMapperTest(){
|
||||
public void courseMapperTest() {
|
||||
|
||||
Course course = new Course();
|
||||
course.setName("测试课程");
|
||||
@ -36,7 +42,7 @@ class Test05ApplicationTests {
|
||||
courseMapper.deleteCourse(course);
|
||||
}
|
||||
courseMapper.insertCourse(course);
|
||||
if (course.getId()==-1){
|
||||
if (course.getId() == -1) {
|
||||
System.out.println("课程添加出阿信错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
@ -58,50 +64,17 @@ class Test05ApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scoreSelectTest(){
|
||||
Score score = new Score();
|
||||
List<Score> result = scoreMapper.selectScore(score);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scoreInsertTest(){
|
||||
Score score = new Score();
|
||||
score.setN_COURSE_ID(22);
|
||||
score.setN_STUDENT_ID(22);
|
||||
score.setF_SCORE(1.0F);
|
||||
scoreMapper.insertScore(score);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scoreUpdateTest(){
|
||||
Score score = new Score();
|
||||
score.setN_COURSE_ID(22);
|
||||
score.setN_STUDENT_ID(22);
|
||||
score.setF_SCORE(2.0F);
|
||||
scoreMapper.updateScore(score);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scoreDeleteTest(){
|
||||
Score score = new Score();
|
||||
score.setN_COURSE_ID(22);
|
||||
score.setN_STUDENT_ID(22);
|
||||
scoreMapper.deleteScore(score);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studentMapperTest(){
|
||||
public void studentMapperTest() {
|
||||
Student student = new Student();
|
||||
student.setVC_STUDENT_CODE("2020202");
|
||||
student.setN_MAJOR(2);
|
||||
student.setVC_STUDENT_NAME("测试学生");
|
||||
student.setN_SEX(1);
|
||||
student.setN_GRADE(2022);
|
||||
student.setCode("2020202");
|
||||
student.setMajor(2);
|
||||
student.setName("测试学生");
|
||||
student.setSex(1);
|
||||
student.setGrade(2022);
|
||||
//添加学生
|
||||
studentMapper.insertStudent(student);
|
||||
System.out.println(student.getN_STUDENT_ID());
|
||||
if (student.getN_STUDENT_ID()==-1) {
|
||||
System.out.println(student.getId());
|
||||
if (student.getId() == -1) {
|
||||
System.out.println("学生信息添加出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
@ -113,14 +86,14 @@ class Test05ApplicationTests {
|
||||
}
|
||||
System.out.println(selectResult);
|
||||
//修改学生
|
||||
student.setN_GRADE(2023);
|
||||
student.setGrade(2023);
|
||||
studentMapper.updateStudent(student);
|
||||
selectResult = studentMapper.selectStudent(student, 0, 10);
|
||||
if (selectResult.size() != 1) {
|
||||
System.out.println("学生信息查询出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
if (selectResult.getFirst().getN_GRADE() != 2023) {
|
||||
if (selectResult.getFirst().getGrade() != 2023) {
|
||||
System.out.println("学生信息修改出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
@ -133,7 +106,7 @@ class Test05ApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void teacherMapperTest(){
|
||||
public void teacherMapperTest() {
|
||||
Teacher teacher = new Teacher();
|
||||
teacher.setVC_TEACHER_NAME("测试老师");
|
||||
teacher.setN_EDUC(2);
|
||||
@ -149,7 +122,7 @@ class Test05ApplicationTests {
|
||||
}
|
||||
//查询老师
|
||||
List<Teacher> selectResult = teacherMapper.selectTeacher(new Teacher());
|
||||
if (selectResult.isEmpty()){
|
||||
if (selectResult.isEmpty()) {
|
||||
System.out.println("查询老师信息出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
@ -158,65 +131,76 @@ class Test05ApplicationTests {
|
||||
//修改老师
|
||||
teacherMapper.updateTeacher(teacher);
|
||||
selectResult = teacherMapper.selectTeacher(teacher);
|
||||
if (selectResult.size() != 1){
|
||||
if (selectResult.size() != 1) {
|
||||
System.out.println("查询老师信息出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
if (selectResult.getFirst().getN_SEX()!=0) {
|
||||
if (selectResult.getFirst().getN_SEX() != 0) {
|
||||
System.out.println("老师信息修改出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
//删除老师
|
||||
teacherMapper.deleteTeacher(teacher);
|
||||
selectResult = teacherMapper.selectTeacher(teacher);
|
||||
if (!selectResult.isEmpty()){
|
||||
if (!selectResult.isEmpty()) {
|
||||
System.out.println("老师信息删除出现错误");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userMapperTest(){
|
||||
public void userMapperTest() {
|
||||
User user;
|
||||
user = userMapper.selectUserByName("测试用户");
|
||||
if (user == null) {
|
||||
user = new User();
|
||||
}else{
|
||||
} else {
|
||||
userMapper.deleteUser(user);
|
||||
}
|
||||
user.setVC_PASSWORD("123456");
|
||||
user.setVC_LOGIN_NAME("测试用户");
|
||||
user.setPassword("123456");
|
||||
user.setName("测试用户");
|
||||
userMapper.insertUser(user);
|
||||
if (user.getN_USER_ID()==-1) {
|
||||
if (user.getId() == -1) {
|
||||
System.out.println("添加用户出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
List<User> selectResult = userMapper.selectUser(new User());
|
||||
if (selectResult.isEmpty()){
|
||||
List<User> selectResult = userMapper.selectUser(new User(), 0, 10);
|
||||
if (selectResult.isEmpty()) {
|
||||
System.out.println("查询用户出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
System.out.println(selectResult);
|
||||
user.setVC_PASSWORD("654321");
|
||||
user.setPassword("654321");
|
||||
userMapper.updateUser(user);
|
||||
selectResult = userMapper.selectUser(user);
|
||||
if (selectResult.size()!=1){
|
||||
selectResult = userMapper.selectUser(user, 0, 10);
|
||||
if (selectResult.size() != 1) {
|
||||
System.out.println("查询用户失败");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
if (!selectResult.getFirst().getVC_PASSWORD().equals(user.getVC_PASSWORD())) {
|
||||
if (!selectResult.getFirst().getPassword().equals(user.getPassword())) {
|
||||
System.out.println("修改用户出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
User selectUser = userMapper.selectUserByName(user.getVC_LOGIN_NAME());
|
||||
if (selectUser==null){
|
||||
User selectUser = userMapper.selectUserByName(user.getName());
|
||||
if (selectUser == null) {
|
||||
System.out.println("用户定位失败");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
userMapper.deleteUser(user);
|
||||
selectResult = userMapper.selectUser(user);
|
||||
if (!selectResult.isEmpty()){
|
||||
selectResult = userMapper.selectUser(user, 0, 10);
|
||||
if (!selectResult.isEmpty()) {
|
||||
System.out.println("删除用户失败");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void genJwtTest(){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("id", "1");
|
||||
map.put("name", "tom");
|
||||
String jwt = JwtUtils.getJwt(map);
|
||||
System.out.println(jwt);
|
||||
Map<String, Object> result = JwtUtils.parseJwt(jwt);
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user