首页>代码>基于SpringBoot+mybatis+Jsp的日记记录系统代码分享>/diary/src/main/java/com/rabbit/diary/bean/core/GlobalExceptionHandler.java
package com.rabbit.diary.bean.core; import cn.dev33.satoken.exception.NotLoginException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; /** * 全局异常处理 * 一般来说,全局异常处理只是一种兜底的异常处理策略,也就是说提倡自己处理异常。 * 但现在其实很多人都喜欢直接在代码中抛异常,全部交给@RestControllerAdvice处理 */ @RestControllerAdvice public class GlobalExceptionHandler { /** * 未登录异常 (直接返回脚本跳转到登录页面) * @param * @return */ @ExceptionHandler(NotLoginException.class) public String handleNotLoginException(NotLoginException bizException) { return "<script>location.href='/login'</script>"; } /** * 业务异常(需要主动抛出) * * @param * @return */ @ExceptionHandler(com.rabbit.diary.bean.core.BizException.class) public com.rabbit.diary.bean.core.Result<com.rabbit.diary.bean.core.ExceptionCodeEnum> handleBizException(com.rabbit.diary.bean.core.BizException bizException) { return com.rabbit.diary.bean.core.Result.error(bizException.getError()); } /** * 运行时异常 * * @param e * @return */ @ExceptionHandler(RuntimeException.class) public com.rabbit.diary.bean.core.Result<com.rabbit.diary.bean.core.ExceptionCodeEnum> handleRunTimeException(RuntimeException e) { return com.rabbit.diary.bean.core.Result.error(com.rabbit.diary.bean.core.ExceptionCodeEnum.ERROR); } }
最近下载更多
wanglinddad LV54
3月24日
zolscy LV12
3月21日
rain112 LV30
2月6日
全栈小陈 LV4
1月21日
酷酷的轲 LV10
2023年6月29日
微信网友_6499449700175872 LV4
2023年5月31日
980363152 LV7
2023年5月15日
最代码官方 LV167
2023年5月14日
最近浏览更多
2716804680 LV9
4月20日
微信网友_6927932988952576 LV12
3月31日
zolscy LV12
3月21日
wanglinddad LV54
3月19日
sunlzh888888 LV28
3月16日
quartz LV7
3月13日
微信网友_6888487558615040 LV6
3月1日
haozhilang LV8
2月27日
lichengai LV7
2月26日
rain112 LV30
2月6日