JSTL中怎么遍历获取MAP 的键 和值
List<Record>rolelist = RoleModel.roleDao.getRolelist();
List<Map<String, String>>rolesMap = new ArrayList<Map<String, String>>();
for(Record role : rolelist){
Map<String, String> map=new HashMap<String,String>();
map.put(role.getStr("r_name"), ","+role.getStr("role_id")+",");
rolesMap.add(map);
}
System.out.println(rolesMap.size());
setAttr("maplist", rolesMap);
setAttr("flowstep", flowstep);
前台遍历取不到(entry.key和entry.value取不到要怎么取啊)<c:forEach items="${maplist}" var="entry">
<span>
<input type="checkbox" name="role_id" value="${entry.value}" class="rids"/>
<span>${entry.key}</span>
</span>
</c:forEach>
1 回答
翻阅古今
TA贡献1780条经验 获得超5个赞
maplist
(rolesMap
)是List套Map,所以<c:forEach>
也要套两层:
<c:forEach items="${maplist}" var="map">
<c:forEach items="${map}" var="entry">
<span>
<input type="checkbox" name="role_id" value="${entry.value}" class="rids"/>
<span>${entry.key}</span>
</span>
</c:forEach>
</c:forEach>
添加回答
举报
0/150
提交
取消