perf(修改): 使用Redis登录、修改Redis存入和未找到用户提示

This commit is contained in:
bunny 2024-03-18 21:00:53 +08:00
parent 46c5eade72
commit 5f927f2e5a
2 changed files with 3 additions and 3 deletions

View File

@ -1,8 +1,8 @@
package com.sky.common.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sky.common.interceptor.JwtTokenUserInterceptor;
import com.sky.common.interceptor.RedisTokenAdminInterceptor;
import com.sky.common.json.JacksonObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@ -45,7 +45,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
// 创建一个消息转换器对象
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
// 需要为消息转换器设置一个对象转换器对象转换器可以将Java对象序列化为json数据
converter.setObjectMapper(new JacksonObjectMapper());
converter.setObjectMapper(new ObjectMapper());
// 将自己的消息转化器加入容器中
converters.add(0, converter);
}

View File

@ -47,6 +47,7 @@ public class EmployeeServiceImpl implements EmployeeService {
String username = employeeLoginDTO.getUsername();
String password = employeeLoginDTO.getPassword();
String token = UUID.randomUUID().toString();
// 1根据用户名查询数据库中的数据
Employee employee = employeeMapper.getByUsername(username);
@ -66,7 +67,6 @@ public class EmployeeServiceImpl implements EmployeeService {
if (Objects.equals(employee.getStatus(), StatusConstant.DISABLE)) {
throw new AccountLockedException(MessageConstant.ACCOUNT_LOCKED);
}
// 使用userId存入登录信息
redisTemplate.opsForValue().set(token, employee.getId(), 7, TimeUnit.DAYS);
// 3返回实体对象