最近在一個(gè)項目中,要將一個(gè)list在客戶(hù)端輸出,而list里面的每個(gè)值不是bean,而是map,想好好久,想了個(gè)辦法,可以實(shí)現,代碼如下
arraylist testlist=new arraylist();
hashmap testmap1=new hashmap();
testmap1.put("grade","七年級");
testmap1.put("class","一班");
testmap1.put("master","張三");
testlist.add(testmap1);
hashmap testmap2=new hashmap();
testmap2.put("grade","八年級");
testmap2.put("class","二班");
testmap2.put("master","張三");
testlist.add(testmap2);
hashmap testmap3=new hashmap();
testmap3.put("grade","九年級");
testmap3.put("class","五班");
testmap3.put("master","李四");
testlist.add(testmap3);
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#0033cc" name="tablelist">
<tr><td>master</td><td>class</td><td>grade</td></tr>
<logic:iterate id="element" indexid="ind" name="testlist" >
<tr>
<td>
<logic:iterate id="elementvalue" indexid="idx" name="element">
<logic:equal name="elementvalue" property="key" value="master">
<bean:write name="elementvalue" property="value"/>
</logic:equal>
</logic:iterate>
</td>
<td> <logic:iterate id="elementvalue" indexid="idx" name="element">
<logic:equal name="elementvalue" property="key" value="class">
<bean:write name="elementvalue" property="value"/>
</logic:equal>
</logic:iterate>
</td>
<td><logic:iterate id="elementvalue" indexid="idx" name="element">
<logic:equal name="elementvalue" property="key" value="grade">
<bean:write name="elementvalue" property="value"/>
</logic:equal>
</logic:iterate>
</td>
</tr>
</logic:iterate>
</table>
聯(lián)系客服