赞
踩
新建一个类,加上注释两个
- @ControllerAdvice(basePackages="com.example.controller")
- public class GlobalExceptionHandler {
-
- private static final Log log = LogFactory.get();
-
-
- //统一异常处理@ExceptionHandler,主要用于Exception
- @ExceptionHandler(Exception.class)
- @ResponseBody//返回json串
- public Result error(HttpServletRequest request, Exception e){
- log.error("异常信息:",e);
- return Result.error();
- }
-
- @ExceptionHandler(CustomException.class)
- @ResponseBody//返回json串
- public Result customError(HttpServletRequest request, CustomException e){
- return Result.error(e.getCode(), e.getMsg());
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。