从头认识Spring-1.14 SpEl表达式(1)-简介与嵌入值
来源:互联网 发布:mac深圳 编辑:程序博客网 时间:2024/05/16 13:43
这一章节我们来讨论一下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;}@Overridepublic 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 {@Autowiredprivate ApplicationContext applicationContext;@Testpublic 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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsdhttp://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsdhttp://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
我的github:https://github.com/raylee2015/my_new_spring
0 0
- 从头认识Spring-1.14 SpEl表达式(1)-简介与嵌入值
- 从头认识Spring-1.14 SpEl表达式(2)-嵌入Bean、Bean的属性和Bean的方法
- 从头认识Spring-1.14 SpEl表达式(3)-SpEl表达式的两个坑:Bean的顺序与Bean的toString方法
- 从头认识Spring-1.15 对SpEl的值的操作(3)-逻辑运算以及条件表达式
- 从头认识Spring-1.15 对SpEl的值的操作(1)-数值运算
- 从头认识Spring-1.15 对SpEl的值的操作(2)-对比值
- Spring表达式语言SpEL简介
- 从头认识Spring-2.6 在注解中使用表达式@Value(1)-注入普通值
- (四)Spring SPEL表达式
- 从头认识Spring-1.16 SpEl对集合的操作(1)-建立集合以及访问集合的元素,以<util:list/>为例
- 从头认识Spring-1.16 SpEl对集合的操作(2)-查询集合以及投影元素集合
- Spring-10 , Spring表达式语言(SpEL)
- 从头认识Spring-2.6 在注解中使用表达式@Value(2)-使用表达式注入其他对象的值
- Spring 框架表达式语言(SpEL)
- Spring 的El 表达式 (SpEL)
- (六)Spring表达式语言SpEl
- SpEL(Spring Expression Language)表达式语言
- Spring Security3 SpEL表达式
- 产品经理常用的那些图
- uva11464 - Age Sort
- pthread condition mutex
- Java中file类getPath(),getAbsolutePath(),getCanonicalPath()方法区别
- IPC(Inner Process Comunication)机制基本了解
- 从头认识Spring-1.14 SpEl表达式(1)-简介与嵌入值
- java中split()特殊符号"." "|" "*" "\" "]"
- pig安装和配置 详细教程
- Android studio的加速
- cocos2d-x核心概念(三)——精灵,场景与层
- select,poll和epoll的区别
- watch
- 汽车出行服务-架构设计
- 网站改版公测,手机/kindle大奖等你来拿!