Browse Source

feat: 用户和角色相关增删改查

haihang
whh 4 months ago
parent
commit
e588e8de6c
  1. 17
      document/src/main/java/com/haihang/config/WebExceptionAdvice.java
  2. 4
      document/src/main/java/com/haihang/utils/LoginInterceptor.java

17
document/src/main/java/com/haihang/config/WebExceptionAdvice.java

@ -0,0 +1,17 @@
package com.haihang.config;
import com.haihang.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class WebExceptionAdvice {
@ExceptionHandler(RuntimeException.class)
public Result handleRuntimeException(RuntimeException e) {
log.error(e.toString(), e);
return Result.fail("服务器异常:"+e.getMessage());
}
}

4
document/src/main/java/com/haihang/utils/LoginInterceptor.java

@ -38,7 +38,7 @@ public class LoginInterceptor implements HandlerInterceptor {
String token = request.getHeader("authorization"); String token = request.getHeader("authorization");
if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {
//前端没传 //前端没传
throw new Exception("前端没有携带token!"); throw new RuntimeException("前端没有携带token!");
} }
//从redis中获取用户 //从redis中获取用户
@ -47,7 +47,7 @@ public class LoginInterceptor implements HandlerInterceptor {
.entries(LOGIN_USER_KEY + token); .entries(LOGIN_USER_KEY + token);
//前端的这个token没有值 //前端的这个token没有值
if (userMap.isEmpty()) { if (userMap.isEmpty()) {
throw new Exception("无效token!!"); throw new RuntimeException("无效token!!");
} }
// //hash转UserDTO存入ThreadLocal // //hash转UserDTO存入ThreadLocal

Loading…
Cancel
Save