Spring MVC控制器返回HTML
我试图将HTML返回到我的Spring MVC控制器时遇到了一个问题。
它看起来像这样:
@RequestMapping(value = QUESTION_GROUP_CREATE_URL, method = RequestMethod.POST) public @ResponseBody String createQuestionGroup(@RequestBody JsonQuestionGroup questionGroup, HttpServletResponse response) { // questionGroup - this comes OK. response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); return ""; }
我的Spring配置:
json=application/json xml=application/xml html=application/html
我看到firebug响应就像: {"String":"
"}我怎么能告诉这个方法发送简单的HTML作为响应?
像这样更改你的Spring配置: html=text/html
并将produces = MediaType.TEXT_HTML_VALUE
添加到你的@RequestMapping
注释中。