Spring EL方法调用实例
Spring EL在注解的形式
package com.yiibai.core; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; @Component("customerBean")
public class Customer { @Value("#{'yiibai'.toUpperCase()}")
private String name; @Value("#{priceBean.getSpecialPrice()}")
private double amount; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public double getAmount() {
return amount;
} public void setAmount(double amount) {
this.amount = amount;
} @Override
public String toString() {
return "Customer [name=" + name + ", amount=" + amount + "]";
} }
package com.yiibai.core;
import org.springframework.stereotype.Component;
@Component("priceBean")
public class Price {
public double getSpecialPrice() {
return new Double(199.09);
}
}
输出
Customer [name=YIIBAI, amount=199.09]
一点解释
@Value("#{'yiibai'.toUpperCase()}")
private String name;
在 ‘priceBean‘ Bean上调用getSpecialPrice() 方法
@Value("#{priceBean.getSpecialPrice()}")
private double amount;
Spring EL在XML的形式
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="customerBean" class="com.yiibai.core.Customer">
<property name="name" value="#{'yiibai'.toUpperCase()}" />
<property name="amount" value="#{priceBean.getSpecialPrice()}" />
</bean> <bean id="priceBean" class="com.yiibai.core.Price" /> </beans>
输出
Customer [name=YIIBAI, amount=199.09]
Spring EL方法调用实例的更多相关文章
- Spring EL bean引用实例
在Spring EL,可以使用点(.)符号嵌套属性参考一个bean.例如,“bean.property_name”. public class Customer { @Value("#{ad ...
- Spring EL hello world实例
Spring EL与OGNL和JSF EL相似,计算评估或在bean创建时执行.此外,所有的Spring表达式都可以通过XML或注解. 在本教程中,我们将学习如何使用Spring表达式语言(SpEL) ...
- Spring 内部方法调用失效问题(AOP)
AOP使用的是动态代理的机制,它会给类生成一个代理类,事务的相关操作都在代理类上完成.内部方式使用this调用方式时,使用的是实例调用,并没有通过代理类调用方法,所以会导致事务失效. 解决办法 方式一 ...
- 反射的妙用-类名方法名做参数进行方法调用实例demo
首先声明一点,大家都会说反射的效率低下,但是大多数的框架能少了反射吗?当反射能为我们带来代码上的方便就可以用,如有不当之处还望大家指出 1,项目结构图如下所示:一个ClassLb类库项目,一个为测试用 ...
- Spring EL表达式和资源调用
Spring EL表达式 Spring EL-Spring表达式语言,支持在xml和注解中使用表达式,类似于在jsp的EL表达式语言. Spring 开发中经常涉及调用各种资源的情况, ...
- spring声明式事务 同一类内方法调用事务失效
只要避开Spring目前的AOP实现上的限制,要么都声明要事务,要么分开成两个类,要么直接在方法里使用编程式事务 [问题] Spring的声明式事务,我想就不用多介绍了吧,一句话“自从用了Spring ...
- Spring Boot实战笔记(二)-- Spring常用配置(Scope、Spring EL和资源调用)
一.Bean的Scope Scope描述的是Spring容器如何新建Bean实例的.Spring的Scope有以下几种,通过@Scope注解来实现. (1)Singleton:一个Spring容器中只 ...
- spring声明式事务 同一类内方法调用事务失效(转)
原文 https://blog.csdn.net/jiesa/article/details/53438342 [问题] Spring的声明式事务,我想就不用多介绍了吧,一句话“自从用了Spring ...
- Spring学习--静态工厂方法、实例工厂方法创建 Bean
通过调用静态工厂方法创建 bean: 调用静态工厂方法创建 bean 是将对象创建的过程封装到静态方法中 , 当客户端需要对象时 , 只需要简单地调用静态方法 , 而不需要关心创建对象的细节. 要声明 ...
随机推荐
- WireShark出现The NPF driver isn't running的问题
昨天开始尝试装上了wireshark网络监视软件,可是今天打开去总是出现“The NPF driver isn't running.You may have trouble capturing or ...
- beego学习笔记(4):开发文档阅读(3)
通过运行 bee new quickstart 来创建新的项目,其结构如下: quickstart |-- conf | `-- app.conf |-- controllers | `-- defa ...
- 简单优化:Zipalign
Android SDK中包含一个“zipalign”的工具,它能够对打包的应用程序进行优化.在你的应用程序上运行zipalign,使得在运行时Android与应用程序间的交互更加有效率.因此,这种方式 ...
- Roman to Integer & Integer to Roman
题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from ...
- Python爬虫-request的用法
import requests if __name__ == '__main__': #基本用法 #response = requests.get("http://httpbin.org/g ...
- Gitlab在centos7上手工安装
本节内容: 安装包 安装Gitlab 配置Gitlab URL 配置防火墙 执行Gitlab的一些基本设置 环境及条件: 系统:CentOS Linux release 7.5.1804 (Core) ...
- Socket 异步
摘要: System.Net.Sockets.Sockte 类有一组增强功能,提供可供专用的高性能套接字应用程序使用的可选异步模式,SocketAsyncEventArgs 类就是这一组增强功能的一部 ...
- 初拾Java(问题二:缺类异常,无法编译)
昨天,在看JSP页面包含的元素(JSP指令,生命,表达式,动作等)时,拷贝了一个别人的例子来在Myeclipse里运行,结果出现了如下的缺类错误: 多调试两次也会出现如下无法编译的错误: 具体代码如下 ...
- Maven入门使用(一)
一.什么是maven 一般认为maven是项目构建工具+依赖管理工具+项目信息管理工具. maven是一个强大的构建工具,能够帮助我们自动化构建过程. 清理.编译.测试.生成报告.打包.部署都是可以通 ...
- angular4 使用window事件
Angular使用window对象中的事件最好不要像使用jQuery那样使用 如下: 注:写事件直接绑定到window对象上了,组件销毁时这个事件没有解绑 可以使用剪头函数不用声明that 注:这样写 ...