OGNL運算式,ognl

來源:互聯網
上載者:User

OGNL運算式,ognl
OGNL運算式標籤中的值有三種:

1.直接是OGNL運算式。

2.字串需轉義自OGNL運算式。

1)OGNL運算式轉換為字串顯示,需要用''(單引號)引起來。

2)轉為OGNL運算式的字串,需要加%{字串}來轉換

3.只能是字串。

標籤:一、資料標籤

1.property -- 顯示資料

value -- 要顯示的內容,放OGNL運算式 如果要顯示字串,需要用''引起來。

escape -- true/false    預設是true, 改為false顯示html效果標籤

default 預設值,放字串,不是放OGNL

<s:property value="'<h1>HAHA<h1>'" escape="false" default="[這是預設值]"/>

2.set -- 設定一個新變數,賦值

var -- 新變數名

scope --範圍 page/request/session/application

value --變數值,OGNL運算式,字串要加單引號

<s:set var="ah" value="newsList" scope="request"></s:set><s:property value="#request.ah"/>

3.url -- 產生網址

var -- 變數名

value--要產生的URL地址,字串可轉義自OGNL,要手動寫出完整的地址。

action -- 要產生的URL地址,字串可轉義自OGNL,產生出絕對路徑。一般用這個

<s:url var="uu" action="News_getAll"></s:url><s:property value="#uu"/>

 

4.bean -- JavaBean的實作類別

name -- 要執行個體化的Java類

var -- 變數名

5.param -- 產生參數

name -- 標籤名

value -- OGNL運算式,加單引號

<s:bean name="com.itnba.maya.domel.News" var="bbb">    <s:param name="biaoti" value="'這是自訂的標題'"></s:param></s:bean><s:property value="#bbb.biaoti"/>

<s:url var="uu" action="News_getAll">    <s:param name="ids" value="'k001'"></s:param></s:url><s:property value="#uu"/>

 

 

6.date -- 格式化輸出日期
name -- 要格式化的日期值 --- OGNL運算式
format --- 格式化顯示的格式。

<s:date name="date" format="yyyy年MM月dd日" var="mydate"/><s:property value="mydate"/>

二、控制標籤

1.if...else if ...else
test -- 表格式OGNL

2.iterator
var
value--OGNL
status:even,odd,first,last,index,count
begin
end
step

<s:iterator var="aa" value="newsList" status="st"><s:if test="#st.even"><div style="background-color:#666666;"></s:if><s:else><div></s:else><s:property value="#st.index+1"/>.<s:property value="#aa.biaoti"/></div></s:iterator>

 

3.append/merge/subset

var--新的對象名
<param> 子項目

<s:set value="{'aa','bb','cc'}" var="aa"></s:set><s:set value="{'11','22','33'}" var="bb"></s:set><s:append var="all">    <s:param name="one" value="#aa"></s:param>    <s:param name="two" value="#bb"></s:param></s:append>

 

<s:set value="{'aa','bb','cc'}" var="aa"></s:set><s:set value="{'11','22','33'}" var="bb"></s:set><s:merge var="all">    <s:param name="one" value="#aa"></s:param>    <s:param name="two" value="#bb"></s:param></s:merge><s:iterator value="#all"  var="t"><s:property value="#t"/><br></s:iterator>

 


4.generater
seperator--分隔字元
val--被分隔的字串
var -- 分隔成的數組名

<s:generator val="'a,b,c,d'" separator="," var="s"></s:generator><s:iterator value="#s" var="t"><s:property value="#t"/><br></s:iterator>


5.sorted
source --- 集合
comparator -- 對比器對象

<s:set value="{'aaaa','bb','ccc','dddd'}" var="arr"></s:set><s:bean name="com.itnba.maya.domel.Duibiqi" var="duibiqi"></s:bean><s:sort comparator="duibiqi" var="sss" source="#arr" >    <s:iterator var="str">        <s:property value="#str"/><br>    </s:iterator></s:sort><s:property value="#arr.size()"/>

還需要建一個類,實現Comparator介面。用來做對比器

package com.itnba.maya.domel;import java.util.Comparator;public class Duibiqi implements Comparator<String>{     @Override    public int compare(String o1, String o2) {        if(o1.length() > o2.length()){            return -1;        }        else if(o1.length() == o2.length()){            return 0;        }        else{            return 1;        }    }}

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.