Struts2 使用OGNL表示式投影(過濾)

2021-07-24 08:09:09 字數 1283 閱讀 7781

一.集合的投影(過濾)有以下三種方式:

(1).「?#」:投影(過濾)所有符合條件的集合,如:students.;

(2).「^#」:投影(過濾)第乙個符合條件的元素,如:students.; 

(3).「$#」:投影(過濾)最後乙個符合條件的元素,如:students. 。 

注意: .「this」表示集合中的元素;

二.ognl具體使用投影(過濾):

1)建立實體類

public class student
2)建立action類

public class studentaction extends actionsupport 

public void setstudents(liststudents)

@override

public string execute() throws exception

}

3)在struts.xml檔案配置action

/ognl.jsp

4)jsp頁面測試

投影查詢:獲取students中所有uname的列表:選擇查詢:獲取students中所有age>30的uname列表:30}."/>選擇查詢:獲取students中所有age>30並且gender為true的uname列表:

30 && #this.gender}."/>選擇查詢:獲取students中所有age>30並且gender為true的第乙個元素的uname列表:

30 && #this.gender)}."/>選擇查詢:獲取students中所有age>30並且gender為true的最後乙個元素的uname列表:

30 && #this.gender)}."/>

5)執行效果:

三 總結:

投影:選出集合中每個元素的相同屬性組成新的集合

選擇:過濾滿足選擇條件的集合元素

Struts2中OGNL的 , , 使用

ognl是通常要結合struts 2的標誌一起使用,如等。大家經常遇到的問題是 和 這三個符號的使用。主要有三種用途 訪問ognl上下文和action上下文,相當於actioncontext.getcontext 下表有幾個actioncontext中有用的屬性 名稱作用例子 parameters ...

struts 2的OGNL表示式

既然要訪識問資料,必須有個東西裝資料。ognl的裝資料的東西叫 stack context ognl context 可以理解它相當於乙個map.1.它裡面的每個 物件,都應該有個名字,根據名字來訪問。物件名 假如ognl context中有3個物件 foo bar test bar.abc 訪問b...

Struts2之ognl表示式(上)

下面通過乙個例項來講述ognl的使用。在src下新建course和student類其原始碼為 course public class course student public class student建立testognl類,開始使用ognl,然後通過 講述ognl的使用 import ognl....