浏览 1922 次
锁定老帖子 主题:网上ognl的文章有问题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (11) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-02-09
最后修改:2011-02-09
基本上所有文章都是这么描述投影的 ?# 满足条件的所有元素 ^# 满足条件的第一个元素 $# 满足条件的最后一个元素 一个action中,有一个list ,里面存的是bean ,bean中有 username password 里面的值都储存好了,其他各种ognl操作均能正常提取 于是测试投影 <s:property value="list.{?#this.username != 'admin'} "/> <s:property value="list.{^#this.username != 'admin'}"/> 结果显示 [com.beans.User@f7a4ba] [com.beans.User@f7a4ba] 发现结果都是集合 但是按照说明,^表示附和条件的第一个元素,那么返回集合显然不符合此文字说明 结论:文章写的有错误或者本身是bug 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2011-02-09
刚才又试了试,发现ognl返回的虽然还是一个集合
但是如果使用^ ,那么这个集合中的内容确实是唯一的 |
|
返回顶楼 | |
发表时间:2011-03-10
那三个东西本来返回的都是集合,后面只是筛选条件,由符合条件的无素组成的新的集合。
看官方文档呀,http://www.opensymphony.com/ognl/html/LanguageGuide/selection.html#N10300 Selecting First Match In order to get the first match from a list of matches, you could use indexing such as listeners.{? true }[0]. However, this is cumbersome because if the match does not return any results (or if the result list is empty) you will get an ArrayIndexOutOfBoundsException. The selection syntax is also available to select only the first match and return it as a list. If the match does not succeed for any elements an empty list is the result. objects.{^ #this instanceof String } Will return the first element contained in objects that is an instance of the String class. 如果用 [0] 返回给你第一个元素,那有找不到符合条件的元素时就会造成数组越界的异常,所以它安全的给你一个包含第一个符合条件元素的集合,没有的话就是个空集合。 |
|
返回顶楼 | |