我有以下HashMap,我想要迭代并打印这些值。我如何在春季做到这一点?在Spring应用程序中在JSP中迭代HashMap的HashMap
HashMap<Integer, HashMap<String, String>> hm = new HashMap<Integer, HashMap<String, String>>();
我有以下HashMap,我想要迭代并打印这些值。我如何在春季做到这一点?在Spring应用程序中在JSP中迭代HashMap的HashMap
HashMap<Integer, HashMap<String, String>> hm = new HashMap<Integer, HashMap<String, String>>();
您可以使用JSTL迭代HashMap的HashMap。
导入taglib <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
。
尝试这样的:
<c:forEach var="entry" items="${hm}">
Key: <c:out value="${entry.key}"/>
Value: <c:out value="${entry.value}"/>
<c:set var="hm1" value="${Value}">
<c:forEach var="entry" items="${hm1}"/>
Key1: <c:out value="${entry1.key}"/>
Value1: <c:out value="${entry1.value}"/>
</c:forEach>
</c:forEach>
,添加HM对象的ModelAndView然后返回如下。
类yourControllerClass {
公共ModelAndView中的handleRequest(..){
ModelAndView mav = new ModelAndView("yourViewName");
//your hash map iterations
mav.put("hm",hm);
//here first attribute is used to iterate the value in JSP
return mav;
}
在JSP遵循Shreyos回答如上。
这不是Spring或任何其他的web MVC框架(JSF,GWT,Vaadin或其他)的工作,它是普通的JSTL +表达式语言。 –