Spring MVC @ExceptionHandler 的使用

来源:互联网 发布:网易数据 广州 编辑:程序博客网 时间:2024/06/06 03:57

  springMVC 提供了大量的注释方便了我们的开发,给我们提供了很大的便利,例如@RequestBody,@ResponseBody,@ExceptionHandler 等等
  本文主要介绍下@ExceptionHandler的使用方法。代码如下

public class BaseController {    private static final Logger AclLog = LoggerFactory.getLogger(BaseController.class);    @ExceptionHandler(RunTimeException.class)    @ResponseBody    public  Object handleException(Exception ex) {        AclLog.warn("EXCEPTION");        JSONObject json = new JSONObject();          json.put("isError", true);          json.put("msg", ex.getMessage());          return json.toString();          return result;    }}
原创粉丝点击