【发布时间】:2016-12-13 02:43:45
【问题描述】:
我想在 spring 的模型属性中添加 JSONArray 并从 ModelAndView 控制器返回。不能像下面那样做。请求帮助。谢谢!
@RequestMapping(value = "/sample.htm", method = RequestMethod.GET)
public ModelAndView seatRequest( ModelMap model,
HttpServletRequest request,HttpServletResponse response, HttpSession session) throws JSONException, JsonProcessingException {
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonObject.put("0", "val0");
jsonObject.put("1", "val1");
jsonObject.put("2", "val2");
jsonArray.put(jsonObject);
model.addAttribute("jsonData",jsonArray.toString());
return new ModelAndView("sample");
【问题讨论】:
标签: json spring spring-mvc model-view-controller