gpt4 book ai didi

java - spring json 写入的 json 比我想要的多

转载 作者:行者123 更新时间:2023-12-01 05:51:24 26 4
gpt4 key购买 nike

我正在使用json spring view为了从我的 Controller 返回一个简单的 JSON 对象。

问题是它返回的数据比我想要的更多。当我在 Controller 中所做的只是以下操作时,它会返回验证错误和模型内部的内容:

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

如果你看bottom of this page in the docs看来我正在取回 POST 将返回的数据。我不是在发帖子,而是通过直接访问带参数的 URL 来执行 GET。

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

最佳答案

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

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

关于java - spring json 写入的 json 比我想要的多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4571783/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com