//定义exceptionhandler解决未被controller层接收的Exception @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.OK) public Object handlerException(HttpServletRequest request,Exception ex){ CommonReturnType type =new CommonReturnType(); type.setStatus("fail"); type.setData(ex); return type; }
@RequestMapping(value = "/get",method = RequestMethod.GET) @ResponseBody public CommonReturnType getUser(@RequestParam(name="id") int id)throws BusinessException{ UserModel userModel = userService.getUserById(id); if (userModel==null){ throw new BusinessException(EmBusinessError.USER_NOT_EXIST); } UserVO userVO = UserTrans.transferFromModel(userModel); //返回通用对象 return CommonReturnType.create(userVO); }
知道了,我之前就加上了@ResponseBody 了