出于测试原因,我想在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忽略我的返回对象吗? 谢谢!
答案 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()
。