我有下面的HashMap,我想对它进行迭代并打印值。我怎么能在春天做到这一点?
HashMap<Integer, HashMap<String, String>> hm = new HashMap<Integer, HashMap<String, String>>();发布于 2014-04-28 22:35:24
您可以使用JSTL在HashMap of 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>发布于 2014-04-28 23:48:28
在spring控制器类中,将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的答案,如上面所示。
https://stackoverflow.com/questions/23352281
复制相似问题