用户中心
约 529 字大约 2 分钟
2026-04-04
项目地址
知识星球:https://articles.zsxq.com/id_5f36h45rq0io.html 编程导航:https://www.code-nav.cn/course/1790943469757837313
代码地址:https://github.com/731016/usercenter/tree/master
主要技术栈
全局异常处理
统一返回工具
安装umi插件出错

可能是"prepare": "cd .. && husky install superjsonweb/.husky" 替换为这个
项目启动报错

[node:internal/crypto/hash:71 thiskHandle] = new _Hash(algorithm, xofLen)-CSDN博客

springboot初始化模板
https://start.springboot.io/
逻辑删除
逻辑删除 | MyBatis-Plus (baomidou.com)

前台代理不能通过配置,匹配请求前缀
export const request = {
prefix : 'http://127.0.0.1:8090/api'
};异常处理
全局异常处理
@RestControllerAdvice
@Slf4j
public class GlobalExecptionHandler {
@ExceptionHandler(BusinessException.class)
public BaseResponse<?> businessExceptionHandler(BusinessException e) {
log.error("businessException: " + e.getMessage() + ",描述:" + e.getDescription(), e);
return ResultUtils.error(e.getCode(), e.getMessage(), e.getDescription());
}
@ExceptionHandler(RuntimeException.class)
public BaseResponse<?> runtimeExceptionHandler(RuntimeException e) {
log.error("runtimeException", e);
return ResultUtils.error(CodeEnum.SYSTEM_ERROR, e.getMessage(), "");
}
}局部异常处理
@ExceptionHandler(RuntimeException.class)
指定在某个controller类中统一返回
业务异常
public class BusinessException extends RuntimeException {
private final int code;
private final String description;
public BusinessException(String message, int code, String description) {
super(message);
this.code = code;
this.description = description;
}
public BusinessException(CodeEnum errorCode) {
super(errorCode.getMessage() + "^" + errorCode.getDescription());
this.code = errorCode.getCode();
this.description = errorCode.getDescription();
}
public BusinessException(CodeEnum errorCode, String description) {
super(errorCode.getMessage());
this.code = errorCode.getCode();
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
}返回结果
@Data
public class BaseResponse<T> implements Serializable {
private int code;
private T data;
private String message;
private String description;
public BaseResponse(int code, T data, String message, String description) {
this.code = code;
this.data = data;
this.message = message;
this.description = description;
}
public BaseResponse(int code, T data) {
this(code,data,"","");
}
public BaseResponse(CodeEnum codeEnum) {
this(codeEnum.getCode(),null, codeEnum.getMessage(), codeEnum.getDescription());
}
}统一返回工具类
public class ResultUtils {
public static <T> BaseResponse success(T data) {
return new BaseResponse(CodeEnum.SUCCESS_STATUS.getCode(), data, CodeEnum.SUCCESS_STATUS.getMessage(), CodeEnum.SUCCESS_STATUS.getDescription());
}
public static <T> BaseResponse error(T data) {
return new BaseResponse(CodeEnum.ERROR_STATUS.getCode(), data, CodeEnum.ERROR_STATUS.getMessage(), CodeEnum.ERROR_STATUS.getDescription());
}
public static BaseResponse error(int code, String message, String description) {
return new BaseResponse(code, null, message, description);
}
public static <T> BaseResponse error(T data,String description) {
return new BaseResponse(CodeEnum.ERROR_STATUS.getCode(), data, CodeEnum.ERROR_STATUS.getMessage(), description);
}
//使用枚举
public static <T> BaseResponse error(CodeEnum codeEnum) {
return new BaseResponse(codeEnum);
}
public static <T> BaseResponse error(CodeEnum codeEnum, String message, String description) {
return new BaseResponse(codeEnum.getCode(), null, message, description);
}
}贡献者
更新日志
2026/4/5 03:39
查看所有更新日志
fb8bc-更新为vuepress于