feat(新增): 调整项目顺序
This commit is contained in:
parent
56f7d4a8a5
commit
786c8a7183
|
@ -0,0 +1,41 @@
|
||||||
|
package com.atguigu.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.atguigu.constant.MessageConstant;
|
||||||
|
import com.atguigu.spzx.model.vo.result.Result;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class InterceptorUtil {
|
||||||
|
/**
|
||||||
|
* 用户未登录返回响应
|
||||||
|
*
|
||||||
|
* @param response 返回体
|
||||||
|
*/
|
||||||
|
public static void unLoginInterceptor(HttpServletResponse response) throws IOException {
|
||||||
|
log.warn("InterceptorUtil===>用户未登录");
|
||||||
|
customLoginInterceptor(response, MessageConstant.USER_NOT_LOGIN, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建用户登录失败
|
||||||
|
*
|
||||||
|
* @param response HttpServletResponse
|
||||||
|
* @param message 消息
|
||||||
|
* @param data 内容
|
||||||
|
*/
|
||||||
|
public static void customLoginInterceptor(HttpServletResponse response, String message, String data) throws IOException {
|
||||||
|
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
|
response.setContentType("application/json");
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
Result<String> result = new Result<>();
|
||||||
|
result.setCode(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
|
result.setData(data);
|
||||||
|
result.setMessage(message);
|
||||||
|
// 将消息写入响应体
|
||||||
|
response.getWriter().write(JSON.toJSONString(result));
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,10 +1,10 @@
|
||||||
package com.atguigu.exception;
|
package com.atguigu.constant;
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class EnumException {
|
public class ExceptionConstant {
|
||||||
public static final String USER_NOT_FOUND = "用户不存在";
|
public static final String USER_NOT_FOUND = "用户不存在";
|
||||||
public static final String USERNAME_IS_EMPTY = "用户名不能为空";
|
public static final String USERNAME_IS_EMPTY = "用户名不能为空";
|
||||||
public static final String PASSWORD_ERROR = "密码错误";
|
public static final String PASSWORD_ERROR = "密码错误";
|
|
@ -1,12 +1,15 @@
|
||||||
package com.atguigu.context;
|
package com.atguigu.context;
|
||||||
|
|
||||||
|
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||||
|
import com.atguigu.spzx.model.entity.user.UserInfo;
|
||||||
|
|
||||||
public class BaseContext {
|
public class BaseContext {
|
||||||
public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
|
public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
|
||||||
|
public static ThreadLocal<SysUser> sysUserThreadLocal = new ThreadLocal<>();
|
||||||
|
public static ThreadLocal<UserInfo> userInfoThreadLocal = new ThreadLocal<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前用户id
|
* 获取当前用户id
|
||||||
*
|
|
||||||
* @return 用户id
|
|
||||||
*/
|
*/
|
||||||
public static Long getUserId() {
|
public static Long getUserId() {
|
||||||
return threadLocal.get();
|
return threadLocal.get();
|
||||||
|
@ -14,17 +17,57 @@ public class BaseContext {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置用户id
|
* 设置用户id
|
||||||
*
|
|
||||||
* @param userId 用户id
|
|
||||||
*/
|
*/
|
||||||
public static void setUserId(Long userId) {
|
public static void setUserId(Long userId) {
|
||||||
threadLocal.set(userId);
|
threadLocal.set(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前 系统用户实体类
|
||||||
|
*/
|
||||||
|
public static SysUser getSysUser() {
|
||||||
|
return sysUserThreadLocal.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前 系统用户实体类
|
||||||
|
*/
|
||||||
|
public static void setSysUser(SysUser sysUser) {
|
||||||
|
sysUserThreadLocal.set(sysUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前 用户实体类
|
||||||
|
*/
|
||||||
|
public static UserInfo getUserInfo() {
|
||||||
|
return userInfoThreadLocal.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前 用户实体类
|
||||||
|
*/
|
||||||
|
public static void setUserInfo(UserInfo userInfo) {
|
||||||
|
userInfoThreadLocal.set(userInfo);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移出当前id
|
* 移出当前id
|
||||||
*/
|
*/
|
||||||
public static void removeCurrentId() {
|
public static void remove() {
|
||||||
threadLocal.remove();
|
threadLocal.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移出当前 系统用户实体类
|
||||||
|
*/
|
||||||
|
public static void removeSysUser() {
|
||||||
|
sysUserThreadLocal.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移出当前 用户实体类
|
||||||
|
*/
|
||||||
|
public static void removeUserInfo() {
|
||||||
|
userInfoThreadLocal.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.atguigu.json;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
import static com.atguigu.constant.LocalDateTimeConstant.*;
|
||||||
|
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象映射器:基于jackson将Java对象转为json,或者将json转为Java对象
|
||||||
|
* 将JSON解析为Java对象的过程称为 [从JSON反序列化Java对象]
|
||||||
|
* 从Java对象生成JSON的过程称为 [序列化Java对象到JSON]
|
||||||
|
*/
|
||||||
|
public class JacksonObjectMapper extends ObjectMapper {
|
||||||
|
public JacksonObjectMapper() {
|
||||||
|
super();
|
||||||
|
// 收到未知属性时不报异常
|
||||||
|
this.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
|
||||||
|
// 反序列化时,属性不存在的兼容处理
|
||||||
|
this.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
|
|
||||||
|
SimpleModule simpleModule = new SimpleModule()
|
||||||
|
.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)))
|
||||||
|
.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)))
|
||||||
|
.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)))
|
||||||
|
.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)))
|
||||||
|
.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)))
|
||||||
|
.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)));
|
||||||
|
|
||||||
|
// 注册功能模块 例如,可以添加自定义序列化器和反序列化器
|
||||||
|
this.registerModule(simpleModule);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.atguigu.utils;
|
package com.atguigu.lib;
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.atguigu.properties;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "bunny.spzx")
|
||||||
|
@Data
|
||||||
|
public class InterceptorsProperties {
|
||||||
|
private List<String> noAuthUrls;
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -34,8 +34,8 @@ logging:
|
||||||
mybatis:
|
mybatis:
|
||||||
type-aliases-package: com.atguigu.spzx.model
|
type-aliases-package: com.atguigu.spzx.model
|
||||||
mapper-locations: classpath:mapper/*.xml
|
mapper-locations: classpath:mapper/*.xml
|
||||||
config-location: classpath:mybatis-config.xml
|
# config-location: classpath:mybatis-config.xml
|
||||||
# configuration:
|
configuration:
|
||||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
# map-underscore-to-camel-case: true
|
map-underscore-to-camel-case: true
|
||||||
# auto-mapping-behavior: full
|
auto-mapping-behavior: full
|
|
@ -34,8 +34,8 @@ logging:
|
||||||
mybatis:
|
mybatis:
|
||||||
type-aliases-package: com.atguigu.spzx.model
|
type-aliases-package: com.atguigu.spzx.model
|
||||||
mapper-locations: classpath:mapper/*.xml
|
mapper-locations: classpath:mapper/*.xml
|
||||||
config-location: classpath:mybatis-config.xml
|
# config-location: classpath:mybatis-config.xml
|
||||||
# configuration:
|
configuration:
|
||||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
# map-underscore-to-camel-case: true
|
map-underscore-to-camel-case: true
|
||||||
# auto-mapping-behavior: full
|
auto-mapping-behavior: full
|
Loading…
Reference in New Issue