应忽略Controller的返回值

时间:2012-04-21 07:12:49

标签: spring-mvc

出于测试原因,我想在spring-mvc-controller中有一个方法签名,返回值应该被spring忽略:

@RequestMapping(value = "/{uuid}", params = "question", method = RequestMethod.POST)
@ResponseBody
public IAnswer saveAnswer(UiAnswer json, @PathVariable String uuid, @RequestParam("question") String question, HttpServletResponse response) {}

这是一个后期请求,如果一切正常,控制器会收到数据并只响应response.setStatus(HttpServletResponse.SC_OK);

  • @ResponseBody在内部服务器错误500
  • 中死亡
  • 没有@ResponseBody春天尝试解析视图
  • 使用void作为返回值,它可以正常工作

我可以告诉spring忽略我的返回对象吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

@RequestMapping(value = "/{uuid}", params = "question", method = RequestMethod.POST)
@ResponseBody
public void saveAnswer(UiAnswer json, 
                       @PathVariable String uuid, 
                       @RequestParam("question") String question, 
                       HttpServletResponse response) {
    doSaveAnswer(json, uuid, question, response);
}

protected IAnswer doSaveAnswer(UiAnswer json, 
                               String uuid, 
                               String question, 
                               HttpServletResponse response) {
    // your original code here
}

然后单元测试doSaveAnswer()