EL表达式和mybatis ognl表达式式,取数据的区别

温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(2907)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'Ognl方法使用(利用表达式语言获取数据)',
blogAbstract:'WebWork的EL-对象图导航语言(Object Graph Navigation Language, 缩写为OGNL)是作为Web页面脚本的最佳选择。一. 基本特性&&& 1. 访问bean属性&&&&&& 根据JavaBean的规范,bean属性使用诸如getXxx(), setXxx(), isXxx()或者hasXxx()这样标准形式的getter方法或&&&&&& setter方法。其中, isXxx()和hasXxx()形式用于boolean属性。在WebWork中,访问这些属性(不管是获取数据还是&&&&&& 设置数据)都使用形式为xxx的属性引用。',
blogTag:'',
blogUrl:'blog/static/5',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:5,
permalink:'blog/static/5',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}EL表达式与OGNL表达式区别
& &E L(Expression Language)
目的:为了使JSP写起来更加简单。表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 JSP
中简化表达式的方法。
&&1、语法结构
${expression}
2、[ ]与.运算符
EL 提供“.“和“[ ]“两种运算符来存取数据。
当要存取的属性名称中包含一些特殊字符,如.或?等并非字母或数字的符号,就一定要使用“[ ]“。例如:
${ user. My-Name}应当改为${user["My-Name"] }
如果要动态取值时,就可以用“[ ]“来做,而“.“无法做到动态取值。例如:
${sessionScope.user[data]}中data 是一个
EL存取数据的方法很简单,例如:${username}。它的意思是取出某一范围中名称为username的。
因为我们并没有指定哪一个范围的username,所以它会依序从Page、Request、Session、Application范围查找。
OGNL是Object-Graph
Navigation Language的缩写,它是一种功能强大的表达式语言(Expression
Language,简称为EL),通过它简单一致的表达式语法,可以存取对象的任意属性,调用对象的方法,遍历整个对象的结构图,实现字段类型转化等功能。它使用相同的去存取对象的属性。
OGNL是通常要结合Struts
2的标志一起使用。主要是#、%和$这三个符号的使用。
#”主要有三种用途:
访问OGNL上下文和Action上下文,#相当于ActionContext.getContext();下表有几个ActionContext中有用的属性:
名称 作用&
“%”符号的用途是在标志的属性为字符串类型时,计算OGNL的值。
“$”有两个主要的用途,用于在国际化资源文件中,引用OGNL表达式。在Struts 2配置文件
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。需要用el表达式取值的数据,除了对象,最好都是String类型,
jsp EL表达式中令人郁闷的int/float/char博客分类: java webjava开发常见问题分析在EL表达式计算过程中,有朋友会遇到许多奇怪的问题,经常非常郁闷,在此我把这些总结一下,方便查询:1、所有的整数数字字面...
EL表达式中令人郁闷的int/float/char
博客分类:
java webjava开发常见问题分析
在EL表达式计算过程中,有朋友会遇到许多奇怪的问题,经常非常郁闷,在此我把这些总结一下,方便查询:
1、所有的整数数字字面量都是Long类型的;
2、所有小数字面量都是Double类型的;
3、""或''声明的是字符串,即''也是字符串,非char;
4、比较时都是equals比较。
接下来看几个可能出问题的例子,你会遇到一下的几个呢:
如${1+} 结果是多少?
如果在java程序里边运行会得到-,而在jsp el中会得到。
Map&Object, Object& map = new HashMap&Object, Object&();
map.put(new Long(1), 123);
request.setAttribute("map", map);
request.setAttribute("a", new Long(1));
${map[a]} 正确
Map&Object, Object& map = new HashMap&Object, Object&();
map.put(new Integer(1), 123);
request.setAttribute("map", map);
request.setAttribute("a", new Long(1));
request.setAttribute("b", new Integer(1));
Map&Object, Object& map = new HashMap&Object, Object&();
map.put(1.1, 123); //map.put(1.1d, 123);
request.setAttribute("map", map);
request.setAttribute("a", new Double(1.1));
map.a=${map[1.1]}
map.a=${map[a]}
Map&Object, Object& map = new HashMap&Object, Object&();
map.put(1.1f, 123); //map.put(new Float(1.1), 123);
request.setAttribute("map", map);
request.setAttribute("a", new Double(1.1));
request.setAttribute("b", new Float(1.1));
map.a=${map[1.1]}
map.a=${map[a]}
map.a=${map[b]}
结合struts2的ognl表达式
&s:property value="#map = #{'a':123, 'b':234}, ''"/&
---&定义一个map,放入值栈的上下文区
&s:property value="#map['a']"/& ----------&正确,因为其支持char
${map['a']} ------------&错误, 因为'a'在jsp el表达式中是字符串,不能=char。
&s:property value='#map = #{"a":123, "b":234}, ""'/&
---&此时key是字符串
${map['a']}
在EL表达式规范2.2中,定义了:
■ The value of an IntegerLiteral ranges from Long.MIN_VALUE to
Long.MAX_VALUE
■ The value of a FloatingPointLiteral ranges from Double.MIN_VALUE to
Double.MAX_VALUE
在tomcat7.0.6实现中,jer.jar(实现了EL2.2规范):
AstFloatingPoint表示小数,AstInteger表示整数,其定义如下:
public final class AstInteger extends SimpleNode
private volatile N
public AstInteger(int id)
super(id);
protected Number getInteger()
if (this.number == null) {
this.number = new Long(this.image);
} catch (ArithmeticException e1) {
this.number = new BigInteger(this.image);
return this.
public Class&?& getType(EvaluationContext ctx)
throws ELException
return getInteger().getClass();
public Object getValue(EvaluationContext ctx)
throws ELException
return getInteger();
public final class AstFloatingPoint extends SimpleNode
private volatile N
public AstFloatingPoint(int id)
super(id);
public Number getFloatingPoint()
if (this.number == null) {
this.number = new Double(this.image);
} catch (ArithmeticException e0) {
this.number = new BigDecimal(this.image);
return this.
public Object getValue(EvaluationContext ctx)
throws ELException
return getFloatingPoint();
public Class&?& getType(EvaluationContext ctx)
throws ELException
return getFloatingPoint().getClass();
+ - * /实现,此处只看+的:
package org.apache.el.
import javax.el.ELE
import org.apache.el.lang.ELA
import org.apache.el.lang.EvaluationC
public final class AstPlus extends ArithmeticNode
public AstPlus(int id)
super(id);
public Object getValue(EvaluationContext ctx)
throws ELException
Object obj0 = this.children[0].getValue(ctx);
Object obj1 = this.children[1].getValue(ctx);
return ELArithmetic.add(obj0, obj1);
其委托给ELArithmetic.add:
public static final DoubleDelegate DOUBLE = new DoubleDelegate();
public static final LongDelegate LONG = new LongDelegate();
private static final Long ZERO = Long.valueOf(0L);
public static final Number add(Object obj0, Object obj1) {
if ((obj0 == null) && (obj1 == null))
return Long.valueOf(0L);
if (BIGDECIMAL.matches(obj0, obj1))
delegate = BIGDECIMAL;
else if (DOUBLE.matches(obj0, obj1))
if (BIGINTEGER.matches(obj0, obj1))
delegate = BIGDECIMAL;
delegate = DOUBLE;
else if (BIGINTEGER.matches(obj0, obj1))
delegate = BIGINTEGER;
delegate = LONG;
Number num0 = delegate.coerce(obj0);
Number num1 = delegate.coerce(obj1);
return delegate.add(num0, num1);
此处委托给了各种delegate计算,其+的实现:
public static final class LongDelegate extends ELArithmetic
protected Number add(Number num0, Number num1)
return Long.valueOf(num0.longValue() + num1.longValue());
从这里我们可以看出其实现。
而且其规范中都规定了具体字面量的东西:
1.3 Literals
There are literals for boolean, integer, floating point, string, and null in an eval-
expression.
■ Boolean - true and false
■ Integer - As defined by the IntegerLiteral construct in Section 1.19
■ Floating point - As defined by the FloatingPointLiteral construct in
Section 1.19
■ String - With single and double quotes - " is escaped as \", ' is escaped as \',
and \ is escaped as \\. Quotes only need to be escaped in a string value enclosed
in the same type of quote
■ Null - null
也规定了操作符的运算规则,如+ - *:
1.3 Literals
There are literals for boolean, integer, floating point, string, and null in an eval-expression.
■ Boolean - true and false
■ Integer - As defined by the IntegerLiteral construct in Section 1.19
■ Floating point - As defined by the FloatingPointLiteral construct in
Section 1.19
■ String - With single and double quotes - " is escaped as \", ' is escaped as \',and \ is escaped as \\. Quotes only need to be escaped in a string value enclosed in the same type of quote
■ Null - null
■ If operator is -, return A.subtract(B)
■ If operator is *, return A.multiply(B)
■ If A or B is a Float, Double,or String containing ., e,or E:
■ If A or B is BigInteger, coerce both A and B to BigDecimal and apply operator.
■ Otherwise, coerce both A and B to Double and apply operator
■ If A or B is BigInteger, coerce both to BigInteger and then:
■ If operator is +, return A.add(B)
■ If operator is -, return A.subtract(B)
■ If operator is *, return A.multiply(B)
■ Otherwise coerce both A and B to Long and apply operator
■ If operator results in exception, error
如Integer型,直接交给前边介绍的IntegerLiteral。
即规范中其实已经规范了这些,但是就像java里的一些东西,虽然规范规定了(如排序时 很多人有时候使用 return a-b; 如果a是负数则可能溢出),但是还是很容易出错。<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&el表达式跟ognl表达式的区别_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
el表达式跟ognl表达式的区别
上传于||暂无简介
阅读已结束,如果下载本文需要使用1下载券
想免费下载本文?
定制HR最喜欢的简历
你可能喜欢

我要回帖

更多关于 el表达式和jstl的区别 的文章

 

随机推荐