Spring_SqEL的介绍

下面就以一个 例子去说明Spring_SqEL

beans-spel.xml的代码:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"><bean id="address" class="Address"><property name="city" value="beijing"></property><property name="street" value="zhonghuajie"></property></bean><bean id="car" class="Car"><property name="brand" value="baoma" ></property><property name="price" value="100000.00"></property><property name="tyrePerimeter" value="#{T(java.lang.Math).PI * 80}"></property></bean><bean id="person" class="Person"><property name="name" value="#{'chen'}"></property><property name="aqe" value="#{23}"></property><property name="car" value="#{car}"></property><property name="info"  value="#{car.price > 99999.00 ? '金领':'白领'}"></property><property name="address" value="#{address.city}"></property></bean>
</beans>

Car类的代码:

public class Car {public String brand;public double price;public double tyrePerimeter;public String getBrand() {return brand;}public void setBrand(String brand) {this.brand = brand;}public double getPrice() {return price;}public void setPrice(double price) {this.price = price;}public double getTyrePerimeter() {return tyrePerimeter;}public void setTyrePerimeter(double tyrePerimeter) {this.tyrePerimeter = tyrePerimeter;}@Overridepublic String toString() {return "Car{" +"brand='" + brand + '\'' +", price=" + price +", tyrePerimeter=" + tyrePerimeter +'}';}
}

Address类的代码:

public class Address {public String city;public String street;public String getCity() {return city;}public void setCity(String city) {this.city = city;}public String getStreet() {return street;}public void setStreet(String street) {this.street = street;}@Overridepublic String toString() {return "Address{" +"address='" + city + '\'' +", street='" + street + '\'' +'}';}
}

Person类的代码:

public class Person {public String name;public int aqe;public String address;public String info;public Car car;public String getInfo() {return info;}public void setInfo(String info) {this.info = info;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAqe() {return aqe;}public void setAqe(int aqe) {this.aqe = aqe;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}public Car getCar() {return car;}public void setCar(Car car) {this.car = car;}@Overridepublic String toString() {return "Person{" +"name='" + name + '\'' +", aqe=" + aqe +", address=" + address +", info='" + info + '\'' +", car=" + car +'}';}
}

Main类的代码:

import java.sql.SQLException;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class Main {public static void main(String[] args) throws SQLException {ApplicationContext ctx = new ClassPathXmlApplicationContext("beans-spel.xml");Person person = (Person) ctx.getBean("person");System.out.println(person);/*Person per = (Person) ctx.getBean ("per");System.out.println (per);*/}}

输出的结果:

Person{name='chen', aqe=23, address=beijing, info='金领', car=Car{brand='baoma', price=100000.0, tyrePerimeter=251.32741228718345}}

视频对xml的解析:如图:

Spring_SqEL相关推荐

最新文章

  1. Cisco呼吁Arista停止在美国销售产品
  2. 数据库主键设计之思考
  3. UA SIE545 优化理论基础 例题 对偶函数的凸性与次梯度计算
  4. 一个css和js结合的下拉菜单,支持主流浏览器
  5. 【超详细】遍历Windows进程模块
  6. Vue学习笔记进阶篇——Render函数
  7. 查找和为定值的两个数—Leetcode1
  8. HDU 1536 求解SG函数
  9. git远程强制更新到本地
  10. 【翻译】WF从入门到精通(一)
  11. win10家庭版如何开启组策略
  12. Android 应用的启动方式
  13. C语言例题19:折半插入排序
  14. php laravel手册,学习Laravel
  15. windows计划任务下 任务启动失败 错误码 2147942402
  16. EOF经验正交展开(一)——主成分分析
  17. 基于java的enigma的加密程序
  18. Camera 驱动 读取摄像头ID失败问题、低温下Camera打开花屏或者读不到id、概率性读取不到id
  19. 破解希沃立知课堂——查看课件篇
  20. 计算机二级 word 论文格式,(计算机二级word练习3.doc

热门文章

  1. Spring @Transactional 原理解析
  2. linux删除历史操作命令
  3. 生长藤蔓Paint Effects
  4. la是什么牌子_c2h4 la是什么牌子_哪个国家的_什么档次?
  5. STM32F10xxx系统RCC讲解
  6. windows与linux文件互传,实现Linux与windows文件互传
  7. 操作题数据库部分代码
  8. PID2 / 开心的金明(rqn)
  9. redis namespace
  10. 科学家发现大量制备反物质的方法