简体   繁体   English

(关于'final'的问题和)如何从JSTL中的Spring ModelMap访问'myModels'的列表对象内容?

[英](Question about 'final' and) How do I access the list object contents of 'myModels' from the Spring ModelMap in JSTL?

@RequestMapping(value = "/index", method = RequestMethod.GET)
public final String index(final ModelMap model)
{
      List myModels = ArrayList<MyModel>(getMyModels());
      model.addAttribute("mymodel", myModels);
      return "index";
}
  1. In Spring I put the myModels list into the ModelMap to be passed to the "index" view. 在Spring中,我将myModels列表放入ModelMap以传递给“index”视图。 How do I then access those MyModel objects from the JSTL code? 然后,我如何从JSTL代码访问这些MyModel对象?

  2. Is it necessary for this controller method to be final and for the ModelMap parameter to be final ? 这个控制器方法是否必须是final并且ModelMap参数是final

  1. By name, eg <c:out value="${mymodel}"/> . 按名称,例如<c:out value="${mymodel}"/> Every model attribute you add to the ModelMap is made available as a JSP request-scoped attribute. 您添加到ModelMap每个模型属性都可用作JSP请求范围的属性。

  2. "no" and "no", final is irrelevant here - did someone tell you otherwise? “不”和“不”, final在这里无关紧要 - 有人告诉你了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM