从头认识Spring-1.14 SpEl表达式(1)-简单介绍与嵌入值
这一章节我们来讨论一下SpEl表达式的简单介绍与嵌入值。
1.SpEl表达式简单介绍
Spring Excpression Language (SpEL)语言支持在执行时操作和查询对象
事实上就是在执行的过程中操作对应的对象或者值。
2.SpEl嵌入值
(1)domain
蛋糕类:(不变)
package com.raylee.my_new_spring.my_new_spring.ch01.topic_1_14;
public class Cake {
private int id = 0;
private String name = "";
private double size = 0;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSize() {
return size;
}
public void setSize(double size) {
this.size = size;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
return "cake id:" + id + " name:" + name + " size:" + size;
}
}
(2)測试类:(打印蛋糕对象的属性)
package com.raylee.my_new_spring.my_new_spring.ch01.topic_1_14; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"/com/raylee/my_new_spring/my_new_spring/ch01/topic_1_14/ApplicationContext-test.xml" })
public class CakeTest { @Autowired
private ApplicationContext applicationContext; @Test
public void testCake() {
Cake cake = applicationContext.getBean(Cake.class);
System.out.println(cake);
}
}
(3)配置文件
<? xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="cake"
class="com.raylee.my_new_spring.my_new_spring.ch01.topic_1_14.Cake">
<property name="id" value="#{1}"/>
<property name="name" value="#{'blueberry cheese cake'}"/>
<!-- <property name='name' value='#{"blueberry cheese cake"}'/> -->
<property name="size" value="#{5.5}"/>
</bean> </beans>
通过#{}把实际的值嵌入到对应的属性里面。当然事实上是嵌入值是没什么意思,由于这样已经把程序给写死了。
測试输出:
cake id:1 name:blueberry cheese cake size:5.5
总结:这一章节主要介绍SpEl表达式的简单介绍与嵌入值。
文件夹:http://blog.csdn.net/raylee2007/article/details/50611627
从头认识Spring-1.14 SpEl表达式(1)-简单介绍与嵌入值的更多相关文章
- EL表达式的简单介绍
EL表达式的简单介绍 一.JSP EL语言定义 E L(ExpressionLanguage) 目的:为了使JSP写起来更加简单. 表达式语言的灵感来自于ECMAScript 和 XPath 表达式 ...
- Spring 缓存注解 SpEL 表达式解析
缓存注解上 key.condition.unless 等 SpEL 表达式的解析 SpEl 支持的计算变量: 1)#ai.#pi.#命名参数[i 表示参数下标,从 0 开始] 2)#result:Ca ...
- Spring进阶之路(10)-Advice简单介绍以及通过cglib生成AOP代理对象
Advice简单介绍 1. Before:在目标方法运行之前运行织入.假设Before的处理中没有进行特殊的处理.那么目标方法终于会运行,可是假设想要阻止目标方法运行时.能够通过抛出一个异常来实现.B ...
- 利用SpEL 表达式实现简单的动态分表查询
这里的动态分表查询并不是动态构造sql语句,而是利用SpEL操作同一结构的不同张表. 也可以参考Spring Data Jpa中的章节http://docs.spring.io/spring-data ...
- Spring实战学习笔记之SpEL表达式
在Spring XML配置文件中装配Bean的属性和构造参数都是静态的,而在运行期才知道装配的值,就可以使用SpEL实现 SpEL表达式的首要目标是通过计算获得某个值. ...
- Spring SpEL表达式的理解
Spring的IOC本质就一个容器,也就是一个对象的工厂,我们通过配置文件注册我们的Bean对象,通过他进行对象的组装与床架. SpEL表达式就是一种字符串编程,类似于JS里面的EVAL的作用,通过它 ...
- Spring Security -SpEL表达式
Spring Security -SpEL表达式 开启SpEL表达式 <!-- use-expressions是否开启 SpEL表达式 o.s.s.web.access.expression.W ...
- 【spring boot】SpringBoot初学(2.2)– SpEL表达式读取properties属性到Java对象
前言 github: https://github.com/vergilyn/SpringBootDemo 代码位置:(注意测试方法在,test下的SpelValueApplicationTest.c ...
- Spring系列.SpEL表达式
Spring表达式语言 SpEL语言是一种强大的表达式语言,支持在运行时查询和操作对象.SpEL表达式不一定要创建IOC容器后才能使用.用户完全可以单独调用SpEL的API来独立的使用时SpEL表达式 ...
随机推荐
- python测试开发django-41.crispy-forms设计标签式导航菜单(TabHolder)
前言 xadmin的详情页面主要是用form_layout布局,学会了完全可以不用写html代码,也能做出很好看的页面. xadmin的html页面是用的Bootstrap3框架设计的,layout布 ...
- Swift - 用CATransform3DMakeRotation实现翻页效果
Swift - 用CATransform3DMakeRotation实现翻页效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // ...
- 沿着path路径做动画
沿着path路径做动画 路径 效果 源码 // // ViewController.m // PathAnimation // // Created by YouXianMing on 16/1/26 ...
- spring boot application.properties
1 <properties> <timestamp>${maven.build.timestamp}</timestamp><maven.build.time ...
- 用layer-list实现弧形进度条
本文转载自:http://www.linuxidc.com/Linux/2013-04/82743.htm 之前我有写过如何用style或者是layer-list实现自定义的横向进度条(http:// ...
- 部署包含水晶报表Crystal Reports 的VS.NET2005应用程序[原创]
要部署包含水晶报表Crystal Reports 的应用程序,您需要在生成解决方案之前创建一个安装项目,并且向应用程序中添加必要的合并模块. 1.打开 VS.NET2005 编程IDE. 2.在解决方 ...
- Bootstrap table的基本使用总结
最近在学习BootStrap构建页面,现记录BootStrap table 的一些基本使用如下: HTML文件: <!DOCTYPE html> <html> <meta ...
- Linux下创建可执行bin安装文件
需求及应用场景 1.简化操作.一般的软件安装过程,如果想要精简步骤,我们一般会将需要在命令行中输入的命令写成一个脚本,同时将安装介质准备好.我们将脚本和安装介质上传到生产环境,然后通过执行脚本来完成安 ...
- 架构模式逻辑层模式之:表模块(Table Model)
表模块和领域模型比,有两个显著区别: 1:表模块中的类和数据库表基本一一对应,而领域模型则无此要求: 2:表模块中的类的对象处理表中的所有记录,而领域模型的一个对象代表表中的一行记录: 一般情况下,我 ...
- cannot import name 'main' 解决方案
error description: pip3 install numpy Traceback (most recent call last): File "/usr/bin/pip3&qu ...