OGNL表达式
OGNL表达式语言
一 常量
|
Char |
‘a’ |
|
String |
‘hello’ 或 “hello” 单个字符 /”a/” |
|
Boolean |
true | false |
|
Int |
123 |
注意:string可以用单引号也可以用双引号。但是单个字母 如’a’与”a”是不同的,前者是char, 后者是string。
<ww:property value=”\”a\””> 或<ww:property value’”a”’>
二 操作符号
|
+ - * / mod |
1+1 ‘hello’+’world’ |
|
++ -- |
foo++ |
|
== != |
|
|
in not in |
foo in aList |
|
= 赋值 |
foo=1 |
三 方法调用
class Muppet{
int fun();
}
调用:fun()-10
四 访问静态方法和变量
@some.pkg.SomeClass@CONSTANTS
@some.pkg.SomeClass@someFun()
五 context
|
ActionContext().getContext().getSession().get(“kkk”) |
#session.kkk |
|
ActionContext().getContext().get(“person”) |
#person |
# 符号相当于ActionContext.
ActionContext 中的主要对象: parameters, attr, request, session, application
六 集合操作
list & array访问
|
list.get(0) array[0] |
list[0] array[0] |
|
list.get(0).getName() |
list[0].name |
|
list.size() array.length |
list.size array.length |
|
list.isEmpty() |
list.isEmpty |
|
List list = new ArrayList() list.ad(“foo”); list.add(“bar”); |
{“foo”, “bar”} {1,2,3} |
Map
|
map.get(“foo”) |
map[‘foo’] 或 map.foo |
|
map.get(1) |
map[1] |
|
Map map = new HashMap() map.put(“k1”, “v1”); map.put(“k2”,”v2”); |
#{“k1”:”v1”, “k2”:”v2”} |
七 筛选 与 投影
筛选 collection.{? expr }: #this 代表当前循环到的object
投影 collection.{ expr }
|
children.{name} |
(投影)得到 Collection<String> names, 只有孩子名字的list |
|
children.{?#this.age>2} |
(筛选)得到 collection<Person> age>2的记录 |
|
children.{?#this.age<=2}.{name} |
先筛选再投影 |
|
children.{name+’->’+mother.name} |
(筛选)得到元素为 str->str 的集合 |
NOTE : #的三种用途
1. 引用 ActionContext 中的object #person
2. 动态创建map #{1:’a’, 2:’b’}
3. 对集合进行筛选(#this) #this
发表评论
- 浏览: 5172 次
- 性别:

- 来自: 厦门

- 详细资料
搜索本博客
我的相册
共 2 张
最近加入圈子
最新评论
-
dojo and ajax
很有用的函数!!
-- by cscs31 -
Dojo 与style相关的函数 ...
Lz能加上一些注解和例子就更好了:)
-- by cscs31






评论排行榜