Struts 2 “#” symbol: get the data in the collection and select it
•
Java
Syntax:
list. {?#conditional expression>value}
For example, if a collection contains multiple student objects, obtaining all students older than 10 in this collection is a selection operation.
Example
public class OgnlAction extends ActionSupport{ //定义List类型books变量 private List<Book>books; public List<Book>getBooks(){ return books; } public String execute(){ //初始化books对象 books = new LinkedList<Book>(); //应用add()方法为List类型books变量赋值 books.add(new Book("978-0735619678","编程宝典",50.99)); books.add(new Book("978-0596007867","典型模块大全",35.96)); books.add(new Book("978-0201633610","开发实战宝典",50.19)); books.add(new Book("978-0596527341","范例大全",25.19)); books.add(new Book("978-0735605350","技术开发大全",50.19)); return SUCCESS; } }
<body> <h3>用于过滤集合</h3> <p>书的价格超过50美元的是</p> <ul> <s:iterator value="books.{?#this.price>50}"> <li><s:property value="title"/>-$<s:property value="price"/></li> </s:iterator> </ul> <p>"范例大全"的价格是:<s:property value="books.{?#this.title=='范例大全'}.{price} [0]"/></p> </body>}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码