春天json写了更多json然后我想要

时间:2010-12-31 18:46:36

标签: java json spring spring-mvc spring-json

我正在使用json spring view以便从我的控制器返回一个简单的JSON对象。

问题在于它返回了我想要的更多数据。它正在我的模型中返回验证错误和事情,当我在控制器中执行此操作时:

Map model = new HashMap()
model.put("success", "true");
return new ModelAndView("jsonView", model);

如果你查看bottom of this page in the docs,我看起来就像是要收回POST会返回的数据。我没有做一个帖子,我正在通过使用params直接访问URL来进行GET。

如何让这个lib只返回模型中的数据?

1 个答案:

答案 0 :(得分:0)

我们已经使用了这个库,它已按预期工作。您可以尝试使用以上代码的以下变体来查看它是否有效吗?我们在某些地方使用它......

ModelAndView modelAndView = new ModelAndView("jsonView");
ModelMap map = modelAndView.getModelMap();
map.addAttribute("success", "true");
return modelAndView;