fix: 修复用户更新

This commit is contained in:
Shu Guang 2025-05-18 20:22:36 +08:00
parent de6798dd25
commit cfbea9c2aa
4 changed files with 4830 additions and 5 deletions

View File

@ -1,5 +1,6 @@
package com.example.system.controller;
import com.example.system.mapper.UserMapper;
import com.example.system.model.Result;
import com.example.system.model.UserTable;
import com.example.system.service.UserService;
@ -30,10 +31,12 @@ import java.util.Map;
public class UserController {
private final UserService userService;
private final PasswordEncoder passwordEncoder; // 注入 PasswordEncoder
private final UserMapper userMapper;
public UserController(UserService userService, PasswordEncoder passwordEncoder) {
public UserController(UserService userService, PasswordEncoder passwordEncoder, UserMapper userMapper) {
this.userService = userService;
this.passwordEncoder = passwordEncoder; // 注入 PasswordEncoder
this.userMapper = userMapper;
}
/**
@ -149,11 +152,13 @@ public class UserController {
@PutMapping("/updateOther")
public Object updateOther(UserTable user, HttpServletRequest request) {
String toKen =request.getHeader("Authorization");
System.out.println("Token: " + user);
Claims claims = JWTUtil.checkToken(toKen);
Integer privileges = (Integer) claims.get("userPrivileges");
if (privileges != 0 && !userService.updateOther(user)) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "用户信息更新失败");
}
userMapper.updateOther(user);
return Result.success("用户信息更新成功");
}
/**

View File

@ -42,14 +42,15 @@ public interface UserMapper {
@Select("select user_name from user_table where user_id=#{studentId}")
String getNameById(Integer studentId);
@Update("update user_table SET " +
@Update("UPDATE user_table SET " +
"user_name=#{userName}, s_t_id=#{sTId}, user_password=#{userPassword}, " +
"user_privileges=#{userPrivileges}, college_id=#{collegeId}, major_table_id=#{majorTableId}," +
"teacher_title=#{teacherTitle},birthdate=#{birthdate},gender=#{gender}," +
"phone=#{phone}, email=#{email}, user_password=#{userPassword}" +
"user_privileges=#{userPrivileges}, college_id=#{collegeId}, major_table_id=#{majorTableId}, " +
"teacher_title=#{teacherTitle}, birthdate=#{birthdate}, gender=#{gender}, " +
"phone=#{phone}, email=#{email} " +
"WHERE user_id=#{userId}")
int updateOther(UserTable user);
//获取用户总数量
@Select("SELECT COUNT(user_id) FROM user_table;")
Object getCount();

View File

@ -23,7 +23,13 @@ public class UserServiceImpl implements UserService {
@Transactional
@Override
public boolean updateOther(UserTable user) {
log.info("[updateOther] 收到UserTable: {}", user);
int tmp = userMapper.updateOther(user);
log.info("[updateOther] update SQL影响行数 tmp={}", tmp); // 这样绝不会错过
log.info("[updateOther] update SQL影响行数 tmp={}", tmp); // 这样绝不会错过
log.info("[updateOther] update SQL影响行数 tmp={}", tmp); // 这样绝不会错过
log.info("[updateOther] update SQL影响行数 tmp={}", tmp); // 这样绝不会错过
log.info("[updateOther] update SQL影响行数 tmp={}", tmp); // 这样绝不会错过
if (tmp == 1) {
return true;
}

File diff suppressed because it is too large Load Diff