Spring MVC@ExceptionHandler 的使用

xiaoxiao2021-02-28  130

  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; } }
转载请注明原文地址: https://www.6miu.com/read-37147.html

最新回复(0)