SpEL表达式

来源:互联网 发布:mysql索引上创建 编辑:程序博客网 时间:2024/05/22 16:41
#{T(System).currentTimeMillis()}

T()表达式会将java.lang.System视为java中对应的类型

#{systemProperties['disc.title']}

通过systemProperties对象引用系统属性

#{artistSelector.selectArtist()?.toUpperCase()}

若?左边的内容为null,则不会调用toUpperCase()方法,返回null
T(java.lang.Math).random()
0~1之间的随机数

#{2*T(java.lang.Math).PI *circle.radius}

ID为circle的bean中圆的周长

#{counter.total == 100}#{counter.total eq 100}

结果一样,返回false或者true

#{scoreboard.score > 1000?"Winner":"Loser"}#{disc.title ?: 'Rattle and Hum'}

判断disc.title是否为null,如果是null,表达式结果为Rattle and Hum

#{admin.email matches '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.com'}

返回true或false

#{jukebox.songs[4].title}

ID是jukebox的bean中,songs集合的第五个元素的title的值

#{'This is a test'[3]}

获取字符串中第四个字符,即s

#{jukebox.songs.?[artist eq 'Aerosmith']}

获取集合songs中artist=’Aerosmith’的所有歌曲,得到集合的一个子集

#{jukebox.songs.^[artist eq 'Aerosmith']} //获取集合songs中artist='Aerosmith'的第一首歌曲#{jukebox.songs.$[artist eq 'Aerosmith']} //获取集合songs中artist='Aerosmith'的最后一首歌曲#{jukebox.songs.![title]}//获取title投影到一个新的String集合中#{jukebox.songs.?[artist eq 'Aerosmith'].![title]}//获取Aerosmith所有歌曲的title列表
原创粉丝点击