(Struts2)OGNL札记 # 的用法三
(Struts2)OGNL笔记 # 的用法三
在行选择等计算中,用 #this 代表迭代中的当前对象
Action
public class Boss { private String name; private int age; public Boss(String name, int age) { this.name = name; this.age = age; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return this.name; } } private List<Boss> bossList = new ArrayList<Boss>(); public List<Boss> getBossList() { return bossList; } public void setBossList(List<Boss> bossList) { this.bossList = bossList; } @Override public String execute() { bossList.add(new Boss("曹操", 40)); bossList.add(new Boss("刘备", 35)); bossList.add(new Boss("孙权", 20)); return SUCCESS; }
JSP
大于30的BOSS : <s:property value="bossList.{?#this.age > 30}"/> <br>
结果如下
大于30的BOSS [曹操, 刘备]