spring mvc异常统一处理(ControllerAdvice注解)
2017-10-26 16:37
681 查看
http://blog.csdn.net/chenaschen/article/details/5129156
@ControllerAdvice
public class GlobalExceptionHandler {
private final static AsJEELogger LOG = AsJEELoggerFactory.getLogger(GlobalExceptionHandler.class);
private final static String EXPTION_MSG_KEY = "message";
@ExceptionHandler(BusinessException.class)
@ResponseBody
public void handleBizExp(HttpServletRequest request, Exception ex){
LOG.info("Business exception handler " + ex.getMessage() );
request.getSession(true).setAttribute(EXPTION_MSG_KEY, ex.getMessage());
}
@ExceptionHandler(SQLException.class)
public ModelAndView handSql(Exception ex){
LOG.info("SQL Exception " + ex.getMessage());
ModelAndView mv = new ModelAndView();
mv.addObject("message", ex.getMessage());
mv.setViewName("sql_error");
return mv;
}
}
6
@ControllerAdvice
public class GlobalExceptionHandler {
private final static AsJEELogger LOG = AsJEELoggerFactory.getLogger(GlobalExceptionHandler.class);
private final static String EXPTION_MSG_KEY = "message";
@ExceptionHandler(BusinessException.class)
@ResponseBody
public void handleBizExp(HttpServletRequest request, Exception ex){
LOG.info("Business exception handler " + ex.getMessage() );
request.getSession(true).setAttribute(EXPTION_MSG_KEY, ex.getMessage());
}
@ExceptionHandler(SQLException.class)
public ModelAndView handSql(Exception ex){
LOG.info("SQL Exception " + ex.getMessage());
ModelAndView mv = new ModelAndView();
mv.addObject("message", ex.getMessage());
mv.setViewName("sql_error");
return mv;
}
}
6
相关文章推荐
- spring mvc异常统一处理(ControllerAdvice注解)
- spring mvc异常统一处理(ControllerAdvice注解)
- spring mvc异常统一处理(ControllerAdvice注解)
- spring mvc异常统一处理(ControllerAdvice注解)
- spring mvc异常统一处理(ControllerAdvice注解)
- spring mvc异常统一处理(ControllerAdvice注解)
- spring mvc异常统一处理(ControllerAdvice注解)
- Spring中@ControllerAdvice注解配合@ExceptionHandler实现统一异常处理
- 使用Spring MVC的@ControllerAdvice注解做Json的异常处理
- Spring boot异常统一处理方法:@ControllerAdvice注解的使用、全局异常捕获、自定义异常捕获
- 使用Spring MVC的@ControllerAdvice注解做Json的异常处理
- 使用Spring MVC的@ControllerAdvice注解做Json的异常处理
- ajax和普通请求使用spring mvc在controller中的异常统一处理
- Spring MVC的Controller统一异常处理:HandlerExceptionResolver
- Spring MVC的Controller统一异常处理:HandlerExceptionResolver
- 《Springboot极简教程》系统异常全局统一处理:@ControllerAdvice plus @ExceptionHandler
- SpringBoot 统一异常处理--- @ControllerAdvice 使用
- spring mvc的controller统一异常处理handlerExceptionResolver
- Spring MVC中@ControllerAdvice注解实现全局异常拦截
- @controllerAdvice 统一处理异常(spring-mvc)