@ExceptionHandler(Exception.class)
public Object handlerException(Exception e){
Map<String,Object> map = new HashMap<>();
map.put("code",500);
//如果错误信息长度大于100
if(e.getMessage().length() > 100){
System.out.println(e.getMessage());
map.put("msg","系统异常,请联系管理员!");
}else {
map.put("msg",e.getMessage());
}
return map;
}
java 全局异常处理
于 2022-01-20 16:43:44 首次发布