猿问

JSTL中怎么遍历获取MAP 的键 和值

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>

阿波罗的战车
浏览 521回答 1
1回答

翻阅古今

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>
随时随地看视频慕课网APP

相关分类

Java
我要回答