关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

SpringEL关系式

发布时间:2020-03-10 00:00:00

全文连接: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);
    }

}

四、运作結果

file

网站源码下载:http://pan.baidu.com/s/1i4HlQzb


/template/Home/Zkeys/PC/Static