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;
}
}