learn02
This commit is contained in:
parent
3f8d7e5fc5
commit
058dea58cb
@ -20,7 +20,7 @@
|
|||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<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" />
|
<entry name="D:/software/dev/maven/apache-maven-3.9.9/repository/org/projectlombok/lombok/release/lombok-release.jar" />
|
||||||
</processorPath>
|
</processorPath>
|
||||||
<module name="learn03-springboot" />
|
<module name="learn03-springboot" />
|
||||||
|
|||||||
@ -77,6 +77,12 @@
|
|||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt</artifactId>
|
||||||
|
<version>0.12.3</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -2,7 +2,9 @@ package test05;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||||
|
|
||||||
|
@ServletComponentScan
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Test05Application {
|
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
|
@Mapper
|
||||||
public interface UserMapper {
|
public interface UserMapper {
|
||||||
List<User> selectUser(User user);
|
List<User> selectUser(User user, int page, int pageSize);
|
||||||
User selectUserByName(String username);
|
User selectUserByName(String username);
|
||||||
int insertUser(User user);
|
int insertUser(User user);
|
||||||
int deleteUser(User user);
|
int deleteUser(User user);
|
||||||
|
|||||||
@ -10,20 +10,20 @@ import lombok.NonNull;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class Student {
|
public class Student {
|
||||||
@NonNull
|
@NonNull
|
||||||
private Integer N_STUDENT_ID=-1;
|
private Integer id =-1;
|
||||||
@NonNull
|
@NonNull
|
||||||
private String VC_STUDENT_CODE="";
|
private String code ="";
|
||||||
@NonNull
|
@NonNull
|
||||||
private String VC_STUDENT_NAME="";
|
private String name ="";
|
||||||
@NonNull
|
@NonNull
|
||||||
private Integer N_SEX=-1;
|
private Integer sex =-1;
|
||||||
@NonNull
|
@NonNull
|
||||||
private Integer N_GRADE=-1;
|
private Integer grade =-1;
|
||||||
@NonNull
|
@NonNull
|
||||||
private Integer N_MAJOR=-1;
|
private Integer major =-1;
|
||||||
@NonNull
|
@NonNull
|
||||||
private String VC_DETAIL="";
|
private String detail ="";
|
||||||
public Student(int id){
|
public Student(int id){
|
||||||
N_STUDENT_ID=id;
|
this.id =id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,12 +10,16 @@ import lombok.NonNull;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class User {
|
public class User {
|
||||||
@NonNull
|
@NonNull
|
||||||
private Integer N_USER_ID=-1;
|
private Integer id =-1;
|
||||||
@NonNull
|
@NonNull
|
||||||
private String VC_LOGIN_NAME ="";
|
private String name ="";
|
||||||
@NonNull
|
@NonNull
|
||||||
private String VC_PASSWORD="";
|
private String password ="";
|
||||||
public User(int id){
|
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;
|
package test05.service;
|
||||||
|
|
||||||
|
import test05.pojo.Result;
|
||||||
|
import test05.pojo.User;
|
||||||
|
|
||||||
public interface UserService {
|
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";
|
return "do not set N_COURSE_ID";
|
||||||
}
|
}
|
||||||
if (course.getName().length()<4||course.getName().length()>25){
|
if (course.getName().length()<4||course.getName().length()>25){
|
||||||
return "name too long";
|
return "name invalid";
|
||||||
}
|
}
|
||||||
if (course.getGrade()>3000||course.getGrade()<2000){
|
if (course.getGrade()>3000||course.getGrade()<2000){
|
||||||
return "grade invalid";
|
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,
|
N_TYPE AS type,
|
||||||
F_CREDIT AS credit,
|
F_CREDIT AS credit,
|
||||||
N_MAJOR AS major,
|
N_MAJOR AS major,
|
||||||
|
N_GRADE AS grade,
|
||||||
VC_DETAIL AS detail
|
VC_DETAIL AS detail
|
||||||
FROM t_course
|
FROM t_course
|
||||||
WHERE #{course.id} in (N_COURSE_ID, -1)
|
WHERE #{course.id} in (N_COURSE_ID, -1)
|
||||||
@ -16,19 +17,19 @@
|
|||||||
AND #{course.credit} in (F_CREDIT, -1)
|
AND #{course.credit} in (F_CREDIT, -1)
|
||||||
AND #{course.major} in (N_MAJOR, -1)
|
AND #{course.major} in (N_MAJOR, -1)
|
||||||
AND UPPER(VC_COURSE_NAME) LIKE CONCAT('%', UPPER(#{course.name}), '%')
|
AND UPPER(VC_COURSE_NAME) LIKE CONCAT('%', UPPER(#{course.name}), '%')
|
||||||
ORDER BY N_COURSE_ID
|
ORDER BY N_COURSE_ID DESC
|
||||||
LIMIT #{page}*#{pageSize},#{pageSize}
|
LIMIT (#{page}-1)*#{pageSize},#{pageSize}
|
||||||
</select>
|
</select>
|
||||||
<select id="selectCourseCount" resultType="int">
|
<select id="selectCourseCount" resultType="int">
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM t_course
|
FROM t_course
|
||||||
WHERE #{N_COURSE_ID} in (N_COURSE_ID, -1)
|
WHERE #{id} in (N_COURSE_ID, -1)
|
||||||
AND #{N_TYPE} in (N_TYPE, -1)
|
AND #{type} in (N_TYPE, -1)
|
||||||
AND #{F_CREDIT} in (F_CREDIT, -1)
|
AND #{credit} in (F_CREDIT, -1)
|
||||||
AND #{N_MAJOR} in (N_MAJOR, -1)
|
AND #{major} in (N_MAJOR, -1)
|
||||||
AND UPPER(VC_COURSE_NAME) LIKE CONCAT('%', UPPER(#{VC_COURSE_NAME}), '%')
|
AND UPPER(VC_COURSE_NAME) LIKE CONCAT('%', UPPER(#{name}), '%')
|
||||||
</select>
|
</select>
|
||||||
<insert id="insertCourse" keyProperty="N_COURSE_ID" useGeneratedKeys="true">
|
<insert id="insertCourse" keyProperty="id" useGeneratedKeys="true">
|
||||||
INSERT INTO t_course
|
INSERT INTO t_course
|
||||||
(VC_COURSE_NAME, N_TYPE, F_CREDIT, N_GRADE, N_MAJOR, VC_DETAIL)
|
(VC_COURSE_NAME, N_TYPE, F_CREDIT, N_GRADE, N_MAJOR, VC_DETAIL)
|
||||||
VALUES (#{name}, #{type}, #{credit}, #{grade}, #{major}, #{detail})
|
VALUES (#{name}, #{type}, #{credit}, #{grade}, #{major}, #{detail})
|
||||||
|
|||||||
@ -4,37 +4,43 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="test05.mapper.StudentMapper">
|
<mapper namespace="test05.mapper.StudentMapper">
|
||||||
<select id="selectStudent" resultType="test05.pojo.Student">
|
<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
|
FROM t_student
|
||||||
WHERE #{student.N_STUDENT_ID} in (N_STUDENT_ID, -1)
|
WHERE #{student.id} in (N_STUDENT_ID, -1)
|
||||||
AND VC_STUDENT_CODE LIKE CONCAT('%', #{student.VC_STUDENT_CODE}, '%')
|
AND VC_STUDENT_CODE LIKE CONCAT('%', #{student.code}, '%')
|
||||||
AND VC_STUDENT_NAME LIKE CONCAT('%', #{student.VC_STUDENT_NAME}, '%')
|
AND VC_STUDENT_NAME LIKE CONCAT('%', #{student.name}, '%')
|
||||||
AND #{student.N_SEX} in (N_SEX, -1)
|
AND #{student.sex} in (N_SEX, -1)
|
||||||
AND #{student.N_GRADE} in (N_GRADE, -1)
|
AND #{student.grade} in (N_GRADE, -1)
|
||||||
AND #{student.N_MAJOR} in (N_MAJOR, -1)
|
AND #{student.major} in (N_MAJOR, -1)
|
||||||
AND VC_DETAIL LIKE CONCAT('%', #{student.VC_DETAIL}, '%')
|
AND VC_DETAIL LIKE CONCAT('%', #{student.detail}, '%')
|
||||||
ORDER BY N_STUDENT_ID
|
ORDER BY N_STUDENT_ID DESC
|
||||||
LIMIT #{page}*#{pageSize},#{pageSize}
|
LIMIT (#{page}-1)*#{pageSize},#{pageSize}
|
||||||
</select>
|
</select>
|
||||||
<insert id="insertStudent" useGeneratedKeys="true" keyProperty="N_STUDENT_ID">
|
<insert id="insertStudent" useGeneratedKeys="true" keyProperty="id">
|
||||||
INSERT INTO t_student
|
INSERT INTO t_student
|
||||||
(VC_STUDENT_CODE, VC_STUDENT_NAME, N_SEX, N_GRADE, N_MAJOR, VC_DETAIL)
|
(VC_STUDENT_CODE, VC_STUDENT_NAME, N_SEX, N_GRADE, N_MAJOR, VC_DETAIL)
|
||||||
VALUES
|
VALUES
|
||||||
(#{VC_STUDENT_CODE},#{VC_STUDENT_NAME},#{N_SEX},#{N_GRADE},#{N_MAJOR},#{VC_DETAIL});
|
(#{code},#{name},#{sex},#{grade},#{major},#{detail});
|
||||||
</insert>
|
</insert>
|
||||||
<delete id="deleteStudent">
|
<delete id="deleteStudent">
|
||||||
DELETE
|
DELETE
|
||||||
FROM t_student
|
FROM t_student
|
||||||
WHERE N_STUDENT_ID = #{N_STUDENT_ID};
|
WHERE N_STUDENT_ID = #{id};
|
||||||
</delete>
|
</delete>
|
||||||
<update id="updateStudent">
|
<update id="updateStudent">
|
||||||
UPDATE t_student
|
UPDATE t_student
|
||||||
SET VC_STUDENT_CODE=#{VC_STUDENT_CODE},
|
SET VC_STUDENT_CODE=#{code},
|
||||||
VC_STUDENT_NAME=#{VC_STUDENT_NAME},
|
VC_STUDENT_NAME=#{name},
|
||||||
N_SEX=#{N_SEX},
|
N_SEX=#{sex},
|
||||||
N_GRADE=#{N_GRADE},
|
N_GRADE=#{grade},
|
||||||
N_MAJOR=#{N_MAJOR},
|
N_MAJOR=#{major},
|
||||||
VC_DETAIL=#{VC_DETAIL}
|
VC_DETAIL=#{detail}
|
||||||
WHERE N_STUDENT_ID=#{N_STUDENT_ID};
|
WHERE N_STUDENT_ID=#{id};
|
||||||
</update>
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@ -4,32 +4,38 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="test05.mapper.UserMapper">
|
<mapper namespace="test05.mapper.UserMapper">
|
||||||
<select id="selectUser" resultType="test05.pojo.User">
|
<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
|
FROM t_user
|
||||||
WHERE
|
WHERE
|
||||||
#{N_USER_ID} IN (N_USER_ID, -1)
|
#{user.id} IN (N_USER_ID, -1)
|
||||||
AND VC_LOGIN_NAME LIKE CONCAT('%',#{VC_LOGIN_NAME},'%')
|
AND VC_LOGIN_NAME LIKE CONCAT('%',#{user.name},'%')
|
||||||
AND VC_PASSWORD LIKE CONCAT('%',#{VC_PASSWORD},'%')
|
AND VC_PASSWORD LIKE CONCAT('%',#{user.password},'%')
|
||||||
|
ORDER BY N_USER_ID DESC
|
||||||
|
LIMIT (#{page}-1)*#{pageSize},#{pageSize}
|
||||||
</select>
|
</select>
|
||||||
<insert id="insertUser" useGeneratedKeys="true" keyProperty="N_USER_ID">
|
<insert id="insertUser" useGeneratedKeys="true" keyProperty="id">
|
||||||
INSERT INTO t_user
|
INSERT INTO t_user
|
||||||
(VC_LOGIN_NAME, VC_PASSWORD)
|
(VC_LOGIN_NAME, VC_PASSWORD)
|
||||||
VALUES
|
VALUES
|
||||||
(#{VC_LOGIN_NAME}, #{VC_PASSWORD})
|
(#{name}, #{password})
|
||||||
</insert>
|
</insert>
|
||||||
<update id="updateUser">
|
<update id="updateUser">
|
||||||
UPDATE t_user
|
UPDATE t_user
|
||||||
SET VC_PASSWORD=#{VC_PASSWORD},
|
SET VC_PASSWORD=#{password},
|
||||||
VC_LOGIN_NAME=#{VC_LOGIN_NAME}
|
VC_LOGIN_NAME=#{name}
|
||||||
WHERE N_USER_ID = #{N_USER_ID};
|
WHERE N_USER_ID = #{id};
|
||||||
</update>
|
</update>
|
||||||
<delete id="deleteUser">
|
<delete id="deleteUser">
|
||||||
DELETE
|
DELETE
|
||||||
FROM t_user
|
FROM t_user
|
||||||
WHERE N_USER_ID = #{N_USER_ID}
|
WHERE N_USER_ID = #{id}
|
||||||
</delete>
|
</delete>
|
||||||
<select id="selectUserByName" resultType="test05.pojo.User">
|
<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
|
FROM t_user
|
||||||
WHERE VC_LOGIN_NAME = #{username};
|
WHERE VC_LOGIN_NAME = #{username};
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@ -1,13 +1,19 @@
|
|||||||
package test05;
|
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.junit.jupiter.api.Test;
|
||||||
import org.opentest4j.TestAbortedException;
|
import org.opentest4j.TestAbortedException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import test05.mapper.*;
|
import test05.mapper.*;
|
||||||
import test05.pojo.*;
|
import test05.pojo.*;
|
||||||
|
import test05.utils.JwtUtils;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class Test05ApplicationTests {
|
class Test05ApplicationTests {
|
||||||
@ -57,51 +63,18 @@ 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
|
@Test
|
||||||
public void studentMapperTest() {
|
public void studentMapperTest() {
|
||||||
Student student = new Student();
|
Student student = new Student();
|
||||||
student.setVC_STUDENT_CODE("2020202");
|
student.setCode("2020202");
|
||||||
student.setN_MAJOR(2);
|
student.setMajor(2);
|
||||||
student.setVC_STUDENT_NAME("测试学生");
|
student.setName("测试学生");
|
||||||
student.setN_SEX(1);
|
student.setSex(1);
|
||||||
student.setN_GRADE(2022);
|
student.setGrade(2022);
|
||||||
//添加学生
|
//添加学生
|
||||||
studentMapper.insertStudent(student);
|
studentMapper.insertStudent(student);
|
||||||
System.out.println(student.getN_STUDENT_ID());
|
System.out.println(student.getId());
|
||||||
if (student.getN_STUDENT_ID()==-1) {
|
if (student.getId() == -1) {
|
||||||
System.out.println("学生信息添加出现错误");
|
System.out.println("学生信息添加出现错误");
|
||||||
throw new TestAbortedException();
|
throw new TestAbortedException();
|
||||||
}
|
}
|
||||||
@ -113,14 +86,14 @@ class Test05ApplicationTests {
|
|||||||
}
|
}
|
||||||
System.out.println(selectResult);
|
System.out.println(selectResult);
|
||||||
//修改学生
|
//修改学生
|
||||||
student.setN_GRADE(2023);
|
student.setGrade(2023);
|
||||||
studentMapper.updateStudent(student);
|
studentMapper.updateStudent(student);
|
||||||
selectResult = studentMapper.selectStudent(student, 0, 10);
|
selectResult = studentMapper.selectStudent(student, 0, 10);
|
||||||
if (selectResult.size() != 1) {
|
if (selectResult.size() != 1) {
|
||||||
System.out.println("学生信息查询出现错误");
|
System.out.println("学生信息查询出现错误");
|
||||||
throw new TestAbortedException();
|
throw new TestAbortedException();
|
||||||
}
|
}
|
||||||
if (selectResult.getFirst().getN_GRADE() != 2023) {
|
if (selectResult.getFirst().getGrade() != 2023) {
|
||||||
System.out.println("学生信息修改出现错误");
|
System.out.println("学生信息修改出现错误");
|
||||||
throw new TestAbortedException();
|
throw new TestAbortedException();
|
||||||
}
|
}
|
||||||
@ -183,40 +156,51 @@ class Test05ApplicationTests {
|
|||||||
} else {
|
} else {
|
||||||
userMapper.deleteUser(user);
|
userMapper.deleteUser(user);
|
||||||
}
|
}
|
||||||
user.setVC_PASSWORD("123456");
|
user.setPassword("123456");
|
||||||
user.setVC_LOGIN_NAME("测试用户");
|
user.setName("测试用户");
|
||||||
userMapper.insertUser(user);
|
userMapper.insertUser(user);
|
||||||
if (user.getN_USER_ID()==-1) {
|
if (user.getId() == -1) {
|
||||||
System.out.println("添加用户出现错误");
|
System.out.println("添加用户出现错误");
|
||||||
throw new TestAbortedException();
|
throw new TestAbortedException();
|
||||||
}
|
}
|
||||||
List<User> selectResult = userMapper.selectUser(new User());
|
List<User> selectResult = userMapper.selectUser(new User(), 0, 10);
|
||||||
if (selectResult.isEmpty()) {
|
if (selectResult.isEmpty()) {
|
||||||
System.out.println("查询用户出现错误");
|
System.out.println("查询用户出现错误");
|
||||||
throw new TestAbortedException();
|
throw new TestAbortedException();
|
||||||
}
|
}
|
||||||
System.out.println(selectResult);
|
System.out.println(selectResult);
|
||||||
user.setVC_PASSWORD("654321");
|
user.setPassword("654321");
|
||||||
userMapper.updateUser(user);
|
userMapper.updateUser(user);
|
||||||
selectResult = userMapper.selectUser(user);
|
selectResult = userMapper.selectUser(user, 0, 10);
|
||||||
if (selectResult.size() != 1) {
|
if (selectResult.size() != 1) {
|
||||||
System.out.println("查询用户失败");
|
System.out.println("查询用户失败");
|
||||||
throw new TestAbortedException();
|
throw new TestAbortedException();
|
||||||
}
|
}
|
||||||
if (!selectResult.getFirst().getVC_PASSWORD().equals(user.getVC_PASSWORD())) {
|
if (!selectResult.getFirst().getPassword().equals(user.getPassword())) {
|
||||||
System.out.println("修改用户出现错误");
|
System.out.println("修改用户出现错误");
|
||||||
throw new TestAbortedException();
|
throw new TestAbortedException();
|
||||||
}
|
}
|
||||||
User selectUser = userMapper.selectUserByName(user.getVC_LOGIN_NAME());
|
User selectUser = userMapper.selectUserByName(user.getName());
|
||||||
if (selectUser == null) {
|
if (selectUser == null) {
|
||||||
System.out.println("用户定位失败");
|
System.out.println("用户定位失败");
|
||||||
throw new TestAbortedException();
|
throw new TestAbortedException();
|
||||||
}
|
}
|
||||||
userMapper.deleteUser(user);
|
userMapper.deleteUser(user);
|
||||||
selectResult = userMapper.selectUser(user);
|
selectResult = userMapper.selectUser(user, 0, 10);
|
||||||
if (!selectResult.isEmpty()) {
|
if (!selectResult.isEmpty()) {
|
||||||
System.out.println("删除用户失败");
|
System.out.println("删除用户失败");
|
||||||
throw new TestAbortedException();
|
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