问答详情
源自:3-4 定义通用的返回对象--异常处理01

为什么我有返回,而不是现实空白页

http://img3.mukewang.com/5f4629950001180112480851.jpg

//定义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);
}


提问者:慕妹3325488 2020-08-26 17:23

个回答

  • 慕妹3325488
    2020-08-26 17:48:20

    知道了,我之前就加上了@ResponseBody 了