全文连接:http://www.yiidian.com/spring/spring-el-helloworld.html
在Spring3中就早已适用EL关系式了, Spring Expression Language(SpEL)是类似OGNL和JSF EL的关系式語言, 可以在运作时搭建繁杂关系式, 存储目标特性、启用目标方式等, 并且全部的SpEL都适用XML和Annotation二种方法, 应用的文件格式均为:#{SpEL expression}。
下边的事例,这一事例将展现怎样运用SpEL引入String、Bean到特性中。
一、撰写Bean类
Customer.java package com.yiidian.domain; import java.io.Serializable; /** * * @author http://www.yiidian.com * */ public class Customer implements Serializable{ private String name; private String telephone; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getTelephone() { return telephone; } public void setTelephone(String telephone) { this.telephone = telephone; } }
CustomerDao插口:
/** * * @author http://www.yiidian.com * */ public interface CustomerDao { }
CustomerDaoImpl类:
留意:在这一类中引入Customer目标和custName的字符串数组。
package com.yiidian.dao.impl; import com.yiidian.dao.CustomerDao; import com.yiidian.domain.Customer; /** * @author http://www.yiidian.com * */ public class CustomerDaoImpl implements CustomerDao { private Customer customer; private String custName; public void setCustomer(Customer customer) { this.customer = customer; } public void setCustName(String custName) { this.custName = custName; } @Override public String toString() { return "CustomerDaoImpl [customer=" + customer + ", custName=" + custName + "]"; } }
二、撰写applicationContext.xml
三、撰写检测
package com.yiidian.test; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.yiidian.dao.CustomerDao; /** * @author http://www.yiidian.com * */ public class Demo1 { @Test public void test1() { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); CustomerDao customerDao = (CustomerDao)context.getBean("customerDao"); System.out.println(customerDao); } }
四、运作結果
网站源码下载:http://pan.baidu.com/s/1i4HlQzb
Copyright © 2004-2024 Ynicp.com 版权所有 法律顾问:建纬(昆明)律师事务所 昆明市网翼通科技有限公司 滇ICP备08002592号-4