【发布时间】:2013-12-29 18:53:44
【问题描述】:
以下映射适用于 Spring 3.1,但不适用于 Spring 3.2。 我收到一个 404 错误,说明 table.jsp 文件丢失。相反,“模型”应该序列化为 json。
@RequestMapping(value = {"/table"}, method = RequestMethod.GET, produces="application/json")
public @ResponseBody Model table(Model model, @RequestParam(defaultValue = "1") Integer pg) {
fillListModel(model, pg);
return model;
}
有没有办法在不影响现有代码的情况下解决这个问题?
以下代码可以正常工作:
@RequestMapping(value = {"/table"}, method = RequestMethod.GET, produces="application/json")
public @ResponseBody Model table(Model model, @RequestParam(defaultValue = "1") Integer pg) {
return new User();
}
所以看起来 Spring 无法识别返回模型的目的是为了将其转换为 json 而不是在视图中呈现。
【问题讨论】:
-
Model是 Spring 类还是您的自定义类? -
Model为spring模型:org.springframework.ui.Model
-
这仍然是
Spring 4.2.x的实际问题
标签: java json spring spring-mvc