`
tianhei
  • 浏览: 210385 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

s:iterator 与 s:property

 
阅读更多

4、普通属性
 public String execute(){
   username = "zhangsan";
   password = "123";
 }
 <s:property value="username"/><br>
   <s:property value="password"/><br>

5、自定义对象
 public String execute(){
  userInfo = new UserInfo();
  userInfo.setUsername("hhh");
  userInfo.setPassword("111");
 }
 <s:property value="userInfo.username"/><br>
   <s:property value="userInfo.password"/><br>
 
 6、List(普通属性)
  public String execute(){
  list = new ArrayList<String>();
  list.add("aaa");
  list.add("bbb");
  list.add("ccc");
 }
 <s:iterator value="list" var="var">
    <s:property value="var"/><br>
   </s:iterator>
   或者:
   <s:iterator value="list">
    <s:property/><br>
   </s:iterator>
   
6、List(自定义对象属性)
 public String execute(){
  list = new ArrayList<UserInfo>();
  UserInfo userInfo = new UserInfo();
  userInfo.setUsername("u1");
  userInfo.setPassword("p1");
  userInfo.setRoleInfo(new RoleInfo("r1"));
  list.add(userInfo);
  userInfo = new UserInfo();
  userInfo.setUsername("u2");
  userInfo.setPassword("p2");
  userInfo.setRoleInfo(new RoleInfo("r2"));
  list.add(userInfo);
 }
 <s:iterator value="list" var="var">
    <s:property value="#var.username"/>
    <s:property value="#var.password"/>
    <s:property value="#var.roleInfo.rolename"/><br>
 </s:iterator>
 或者:
 <s:iterator value="list">
    <s:property value="username"/>
    <s:property value="password"/>
    <s:property value="roleInfo.rolename"/><br>
 </s:iterator>
 
7、数组(普通属性)
 public String execute(){
  strs = new String[2];
  strs[0] = "as";
  strs[1] = "asd";
 }
 <s:iterator value="strs">
    <s:property/><br>
   </s:iterator>
 或者:
 <s:iterator value="strs" var="var">
    <s:property value="var"/><br>
   </s:iterator>
   
8、数组(自定义对象属性)
 public String execute(){
  strs = new UserInfo[2];
  UserInfo userInfo = new UserInfo();
  userInfo.setUsername("u11");
  userInfo.setPassword("11");
  strs[0] = userInfo;
  userInfo = new UserInfo();
  userInfo.setUsername("u22");
  userInfo.setPassword("22");
  strs[1] = userInfo;
 }
 <s:iterator value="strs">
    <s:property value="username"/>
    <s:property value="password"/><br>
   </s:iterator>
 或者:
 <s:iterator value="strs" var="var">
    <s:property value="#var.username"/>
    <s:property value="#var.password"/><br>
 </s:iterator>

8、数组(自定义对象属性)
 public String execute(){
  strs = new UserInfo[2];
  UserInfo userInfo = new UserInfo();
  userInfo.setUsername("u11");
  userInfo.setPassword("11");
  userInfo.setRoleInfo(new RoleInfo("r11"));
  strs[0] = userInfo;
  userInfo = new UserInfo();
  userInfo.setUsername("u22");
  userInfo.setPassword("22");
  userInfo.setRoleInfo(new RoleInfo("r22"));
  strs[1] = userInfo;
 }
 <s:iterator value="strs" var="var">
    <s:property value="#var.username"/>
    <s:property value="#var.password"/>
    <s:property value="#var.roleInfo.rolename"/><br>
 </s:iterator>
 或者:
 <s:iterator value="strs">
    <s:property value="username"/>
    <s:property value="password"/>
    <s:property value="roleInfo.rolename"/><br>
 </s:iterator>
 
8、Map(普通属性)
 public String execute(){
  map = new HashMap<String,String>();
  map.put("k1", "v1");
  map.put("k2", "v2");
 }
 <s:iterator value="map" var="var">
    <s:property value="#var.key"/>
    <s:property value="#var.value"/><br>
 </s:iterator>
 或者:
 <s:iterator value="map">
    <s:property value="key"/>
    <s:property value="value"/><br>
 </s:iterator>
 
8、Map(自定义对象属性)
 public String execute(){
  map = new HashMap<String,UserInfo>();
  UserInfo userInfo = new UserInfo();
  userInfo.setUsername("u1");
  userInfo.setPassword("p1");
  userInfo.setRoleInfo(new RoleInfo("r1"));
  map.put("k1", userInfo);
  userInfo = new UserInfo();
  userInfo.setUsername("u2");
  userInfo.setPassword("p2");
  userInfo.setRoleInfo(new RoleInfo("r2"));
  map.put("k2", userInfo);
 }
 <s:iterator value="map" var="var">
    <s:property value="#var.key"/>
    <s:property value="#var.value.username"/>
    <s:property value="#var.value.password"/>
    <s:property value="#var.value.roleInfo.rolename"/><br>
 </s:iterator>
 或者
 <s:iterator value="map">
    <s:property value="key"/>
    <s:property value="value.username"/>
    <s:property value="value.password"/>
    <s:property value="value.roleInfo.rolename"/><br>
 </s:iterator>
 
8、Map嵌套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);
 }
 <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>
 </s:iterator>

4
3
分享到:
评论
3 楼 beyondfengyu 2013-08-03  
总结得很好,考虑的情况很详细,灰常感谢
2 楼 wjxingzhe 2013-06-20  
感谢总结!
1 楼 tfwin2 2011-07-16  
还不错,虽然已经不用S2了,但是这些过去确认没总结过,只是用而已。

相关推荐

Global site tag (gtag.js) - Google Analytics