/**
* Created by Administrator on 2017/7/18.
*/
@ControllerAdvice
public class ExceptionHandle {
@ExceptionHandler(value = Exception.class)
@ResponseBody
public Result handle(Exception e) {
if (e instanceof MyExpection) {
MyExpection myExpection = (MyExpection) e;
return ResultUtil.error(myExpection.getCode(), myExpection.getMessage());
} else {
return ResultUtil.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
}
}
}
Spring MVC全局處理Exception
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.