}
/**
-
拦截捕捉自定义异常 MyException.class
-
@param ex
-
@return
*/
@ExceptionHandler(value = CommonException.class)
public Map myErrorHandler(HttpServletRequest req, CommonException ex) {
Map map = new HashMap();
map.put(“code”, ex.getCode());
map.put(“message”, ex.getMsg());
map.put(“url”, req.getRequestURL());
map.put(“params”, req.getParameterMap());
return map;
}
}
3.controller
@RequestMapping(value = “/login”,method = RequestMethod.POST)
public UserBase login(@RequestParam String account) {
UserBase result = null;
try {
result = userBaseService.userLogin(account);
} catch (Exception e) {
log.error(“用户登录异常={}”,e.getMessage(),e);
throw new CommonException(500,“内部错误”);
}
r