s标签显示后台数据的基本用法以及iterator遍历用法(5)
- UID
- 1066743
|
s标签显示后台数据的基本用法以及iterator遍历用法(5)
Map嵌套Map(自定义对象属性)
java文件中赋值并且set和get map
public String execute(){
map = new TreeMap<String,Map<String,UserInfo>>();
Map<String,UserInfo> innerMap = new TreeMap<String,UserInfo>();
UserInfo userInfo = new UserInfo();
userInfo.setUsername("u1");
userInfo.setPassword("p1");
userInfo.setRoleInfo(new RoleInfo("r1"));
userInfo = new UserInfo();
userInfo.setUsername("u11");
userInfo.setPassword("p11");
userInfo.setRoleInfo(new RoleInfo("r11"));
innerMap.put("k1", userInfo);
innerMap.put("k11", userInfo);
map.put("key1", innerMap);
//////////////////////////
innerMap = new TreeMap<String,UserInfo>();
userInfo = new UserInfo();
userInfo.setUsername("u2");
userInfo.setPassword("p2");
userInfo.setRoleInfo(new RoleInfo("r2"));
userInfo = new UserInfo();
userInfo.setUsername("u22");
userInfo.setPassword("p22");
userInfo.setRoleInfo(new RoleInfo("r22"));
innerMap.put("k2", userInfo);
innerMap.put("k22", userInfo);
map.put("key2", innerMap);
}
JSP页面中
<s:iterator value="map" var="var">
<s:iterator value="value">
<s:property value="#var.key"/>
<s:property value="key"/>
<s:property value="value.username"/>
<s:property value="value.password"/>
<s:property value="value.roleInfo.rolename"/><br>
</s:iterator> |
|
|
|
|
|