perf(修改): 使用Redis登录、修改Redis存入和未找到用户提示
This commit is contained in:
parent
46c5eade72
commit
5f927f2e5a
|
@ -1,8 +1,8 @@
|
||||||
package com.sky.common.config;
|
package com.sky.common.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.sky.common.interceptor.JwtTokenUserInterceptor;
|
import com.sky.common.interceptor.JwtTokenUserInterceptor;
|
||||||
import com.sky.common.interceptor.RedisTokenAdminInterceptor;
|
import com.sky.common.interceptor.RedisTokenAdminInterceptor;
|
||||||
import com.sky.common.json.JacksonObjectMapper;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -45,7 +45,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
// 创建一个消息转换器对象
|
// 创建一个消息转换器对象
|
||||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
||||||
// 需要为消息转换器设置一个对象转换器,对象转换器可以将Java对象序列化为json数据
|
// 需要为消息转换器设置一个对象转换器,对象转换器可以将Java对象序列化为json数据
|
||||||
converter.setObjectMapper(new JacksonObjectMapper());
|
converter.setObjectMapper(new ObjectMapper());
|
||||||
// 将自己的消息转化器加入容器中
|
// 将自己的消息转化器加入容器中
|
||||||
converters.add(0, converter);
|
converters.add(0, converter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||||
String username = employeeLoginDTO.getUsername();
|
String username = employeeLoginDTO.getUsername();
|
||||||
String password = employeeLoginDTO.getPassword();
|
String password = employeeLoginDTO.getPassword();
|
||||||
String token = UUID.randomUUID().toString();
|
String token = UUID.randomUUID().toString();
|
||||||
|
|
||||||
// 1、根据用户名查询数据库中的数据
|
// 1、根据用户名查询数据库中的数据
|
||||||
Employee employee = employeeMapper.getByUsername(username);
|
Employee employee = employeeMapper.getByUsername(username);
|
||||||
|
|
||||||
|
@ -66,7 +67,6 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||||
if (Objects.equals(employee.getStatus(), StatusConstant.DISABLE)) {
|
if (Objects.equals(employee.getStatus(), StatusConstant.DISABLE)) {
|
||||||
throw new AccountLockedException(MessageConstant.ACCOUNT_LOCKED);
|
throw new AccountLockedException(MessageConstant.ACCOUNT_LOCKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用userId存入登录信息
|
// 使用userId存入登录信息
|
||||||
redisTemplate.opsForValue().set(token, employee.getId(), 7, TimeUnit.DAYS);
|
redisTemplate.opsForValue().set(token, employee.getId(), 7, TimeUnit.DAYS);
|
||||||
// 3、返回实体对象
|
// 3、返回实体对象
|
||||||
|
|
Loading…
Reference in New Issue