Spring3.1——Spring表达式语言SpEL
来源:互联网 发布:北京游戏美工薪资水平 编辑:程序博客网 时间:2024/05/19 22:25
创建步骤:
(1)创建ExpressionParser对象。表达式解析器。
(2)调用ExpressionParser对象的parseExpresssion方法解析字符串,得到Expression对象。(3)调用Expression对象的getValue()方法,即可得到表达式的值。
eg1:基本语法
eg2:变量语法
变量语法:
abc.xyz: 获取Context中根对象的getAbc().getXyz()的返回值。
#abc.xyz:获取Context名为abc的对象的getXyz()返回值。
eg3:简化配置文件中的配置,消除子元素
在Spring配置文件中使用Sp EL, 将Sp EL表达式放在 #{} 里面即可。
在Spring配置文件中, 求表达式值的Context就是Spring容器本身
修改前的代码可参考修改前
修改后源码:
<!-- JFrame mainWin = new JFrame("我的窗口"); --><bean id="mainWin" class="javax.swing.JFrame"c:_0="我的窗口"p:visible="true"/><!-- JTextArea jta = new JTextArea(9 ,60); --><bean id="jta" class="javax.swing.JTextArea"c:_0="9"c:_1="60"/><!--mainWin.add( new JScrollPane(jta) );(使用嵌套bean) --><bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"p:targetObject-ref="mainWin"p:targetMethod="add"p:arguments="#{ {new javax.swing.JScrollPane(jta)} }"/><!-- JPanel jp = new JPanel(); --><bean id="jp" class="javax.swing.JPanel"/><!-- mainWin.add(jp , BorderLayout.SOUTH); --><bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"p:targetObject-ref="mainWin"p:targetMethod="add"p:arguments="#{ {jp,T(java.awt.BorderLayout).SOUTH} }"/><!-- JButton okBn = new JButton("确定"); --><bean id="okBn" class="javax.swing.JButton"c:_0="确定"/><!-- jp.add(okBn); --><bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"p:targetObject-ref="jp"p:targetMethod="add"p:arguments="#{ {okBn} }"/><!-- JButton cancelBn = new JButton("取消"); --><bean id="cancelBn" class="javax.swing.JButton" c:_0="取消"/><!-- jp.add(cancelBn); --><bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"p:targetObject-ref="jp"p:targetMethod="add"p:arguments="#{ {cancelBn} }"/><!-- mainWin.pack();--><bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"p:targetObject-ref="mainWin"p:targetMethod="pack"/>
阅读全文
0 0
- Spring3.1——Spring表达式语言SpEL
- 【第五章】Spring表达式语言 之 5.3 SpEL语法 ——跟我学spring3
- 【第五章】Spring表达式语言 之 5.3 SpEL语法 ——跟我学spring3
- 【第五章】Spring表达式语言 之 5.3 SpEL语法 ——跟我学spring3
- 【第五章】Spring表达式语言 之 5.3 SpEL语法 ——跟我学spring3
- 【第五章】Spring表达式语言 之 5.3 SpEL语法 ——跟我学spring3
- 【第五章】Spring表达式语言 之 5.3 SpEL语法 ——跟我学spring3
- 【第五章】Spring表达式语言 之 5.3 SpEL语法 ——跟我学spring3
- 【第五章】Spring表达式语言 之 5.3 SpEL语法 ——跟我学spring3
- 【第五章】Spring表达式语言 之 5.3 SpEL语法 ——跟我学spring3
- Spring3.0 —— 表达式语言(SpEL)
- Spring3 表达式语言(SpEL)介绍
- Spring3 表达式语言(SpEL)介绍
- Spring3的表达式语言 spel
- Spring-----12、Spring3.0提供的表达式语言(spel)
- 【第五章】Spring表达式语言 之 5.1 概述 5.2 SpEL基础 ——跟我学spring3
- 【第五章】Spring表达式语言 之 5.1 概述 5.2 SpEL基础 ——跟我学spring3
- 【第五章】Spring表达式语言 之 5.1 概述 5.2 SpEL基础 ——跟我学spring3
- Linux系统控制文件 /etc/sysctl.conf
- 切图原理
- 秒杀系统架构优化思路
- Keras之父:大多数深度学习论文都是垃圾,炒作AI危害很大
- C++字符串 单词倒置
- Spring3.1——Spring表达式语言SpEL
- Django框架学习笔记(24.缓存实例简介)
- easyDarwin已经无法接入easyNVR
- html中有关于submit的笔记
- 先开个博客看看
- Qt5.10 搭建 Android 开发环境
- 跬步系列
- React全家桶构建一款Web音乐App实战3
- Node.js安装及环境配置之Windows篇