list和map用法java_使用SpringEL操作List和Map集合

原文链接:http://www.yiidian.com/spring/spring-el-bean.html

这个例子演示SpEL表达式怎样从List、Map集合中取值,示例如下:

一、编写Bean类

TestCollection类,用于创建Map和List对象

package com.yiidian.collection;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

/**

*

* @author http://www.yiidian.com

*

*/

public class TestCollection {

private Map nameMap;

private List teleList;

public TestCollection() {

nameMap = new HashMap();

nameMap.put("001", "张三");

nameMap.put("002", "李四");

nameMap.put("003", "王五");

teleList = new ArrayList();

teleList.add("13422223333");

teleList.add("13544446666");

teleList.add("13788889999");

}

public Map getNameMap() {

return nameMap;

}

public void setNameMap(Map nameMap) {

this.nameMap = nameMap;

}

public List getTeleList() {

return teleList;

}

public void setTeleList(List teleList) {

this.teleList = teleList;

}

}

Customer类:

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;

}

@Override

public String toString() {

return "Customer [name=" + name + ", telephone=" + telephone + "]";

}

}

二、配置applicationContext.xml

xmlns:p="http://www.springframework.org/schema/p"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

三、编写测试类

package com.yiidian.test;

import org.junit.Test;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.yiidian.domain.Customer;

/**

* @author http://www.yiidian.com

*

*/

public class Demo1 {

@Test

public void test1() {

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

Customer customer = (Customer)context.getBean("customer");

System.out.println(customer);

}

}

四、运行结果

00b3ce2657db3154929ecde7b9b2d48f.png

源码下载:http://pan.baidu.com/s/1hsCK0S0

欢迎关注我的公众号::一点教程。获得独家整理的学习资源和日常干货推送。

如果您对我的系列教程感兴趣,也可以关注我的网站:yiidian.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值