SpringEL-操作List、Map


这个例子演示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<String, String> nameMap;private List<String> teleList;public TestCollection() {nameMap = new HashMap<String, String>();nameMap.put("001", "张三");nameMap.put("002", "李四");nameMap.put("003", "王五");teleList = new ArrayList<String>();teleList.add("13422223333");teleList.add("13544446666");teleList.add("13788889999");}public Map<String, String> getNameMap() {return nameMap;}public void setNameMap(Map<String, String> nameMap) {this.nameMap = nameMap;}public List<String> getTeleList() {return teleList;}public void setTeleList(List<String> 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;}@Overridepublic String toString() {return "Customer [name=" + name + ", telephone=" + telephone + "]";}}

二、配置applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"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"><bean id="testCollection" class="com.yiidian.collection.TestCollection"></bean><bean id="customer" class="com.yiidian.domain.Customer"><property name="name" value="#{testCollection.nameMap['001']}"/><property name="telephone" value="#{testCollection.teleList[0]}"/></bean></beans>

三、编写测试类

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 {@Testpublic void test1() {ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");Customer customer = (Customer)context.getBean("customer");System.out.println(customer);}}

四、运行结果

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

spring4.x(13)---SpringEL-操作List、Map相关推荐

  1. 13 【操作mysql数据库】

    13 [操作mysql数据库] 1.mysql 介绍 付费的商用数据库: Oracle,典型的高富帅: SQL Server,微软自家产品,Windows定制专款: DB2,IBM的产品,听起来挺高端 ...

  2. Golang——map集合初始化、键值操作、map作为函数参数的使用

    map是一种无序的键值对集合,键是不允许重复的,map是通过hash实现的 map最重要的一点是通过key来快速检索数据,key类似于索引,指向数据的值 引用类型不能作为key map的创建: 格式1 ...

  3. SpringBoot(13)--- 数据库操作(集成MyBatis)

    SpringBoot 数据库操作(集成MyBatis) Spring对持久化的支持,不单只支持JDBC,为各种支持的持久化技术都提供了简单的模板和回调: ORM持久化技术 模板类 JDBC(JdbcT ...

  4. 1.13 golang中的Map

    1. Map map是一种无序的基于key-value的数据结构,Go语言中的map是引用类型,必须初始化才能使用. 1.1.1. map定义 Go语言中 map的定义语法如下 map[KeyType ...

  5. Ubuntu 14.04 64位上安装Valgrind 3.13.0 操作步骤

    关于Valgrind的介绍和使用可以参考: http://blog.csdn.net/fengbingchun/article/details/50196189 在Ubuntu 14.04上可以通过以 ...

  6. 1.13 Predicate操作Collection集合

    使用Java 8新增的Predicate操作Collection集合 Java 8 起为 Collection 集合新增了一个 removeIf(Predicate filter) 方法,该方法将会批 ...

  7. C#之CAD二次开发实例 (13) 图层操作

    # 0. 引言 图层在CAD中也是一个重要的角色,自然而然二次开发也必不可少,先来回顾一下图形数据库,也就是下面这个东西 Database db = HostApplicationServices.W ...

  8. 13.tornado操作之增加用户喜欢的图片展示页+同时展示用户上传的所有图片增加展示图片有多少用户喜欢的功能

    目录: 第一部分:增加用户喜欢的图片展示页 1.基本步骤先走起来--视图+接口+前端模板 (1)编写视图ProfileHandler: (2)编写接口:(app.py文件中加入以下接口) (3)编写前 ...

  9. Cesium从入门到放弃13:鼠标操作习惯设置

    Cesium默认左键平移,中键旋转,右键缩放,但是这些功能都是可以绑定到任意键上的. 以下是将中键和右键功能互换的代码: //设置中键放大缩小viewer.scene.screenSpaceCamer ...

最新文章

  1. 送40本书,人人有份!
  2. 用python和opencv检测图像中的条形码
  3. linux 安装了tomcat 但是一直访问不了怎么办
  4. 联邦学习:AI大规模落地又一革命性突破
  5. node + express + mysql 搭建后台
  6. 深度学习之Windows下安装caffe及配置Python和matlab接口
  7. Windows驱动—Windows应用程序和Windows驱动通信编程
  8. java 多线程,线程安全等定义
  9. 如何有效看文献(一)
  10. 《HTML5 Canvas游戏开发实战》——3.3 自定义画板
  11. MySQL Workbench 导入导出乱码解决方法
  12. sublime test3 php语法错误高亮
  13. Atitit 建立新组织集团模型的框架基本制度与一些原则
  14. Stata:产生唯一数据编码的三种方法
  15. 【基金量化研究系列】大类资产配置研究(四)——基于马科维茨模型的资产配置研究
  16. 9.高性能计算 期末复习
  17. 连接手表_小米手表体验报告(上)
  18. jar启动指定JDK/JRE 安装路径教程
  19. mysql导入报1449_mysqldump 1449错误解决办法
  20. JavaScript:实现字符串是否是有效的电子邮件地址算法(附完整源码)

热门文章

  1. (3)散列函数设计:直接定址法
  2. Java学习日报—消息队列—2021/11/23
  3. 嵌入式Linux系统编程学习之二十七线程的创建和退出
  4. java iso-8859-1_如何在Java中的ISO-8859-1和UTF-8之间转换?
  5. 在c语言中定义共用型数据类型的关键字是,C语言的关键字共有32个,根据关键字的作用,可分其为数据类型关键...
  6. vue-router-2-动态路由配置
  7. android.os.NetworkOnMainThreadException问题
  8. ArrayList 和LinkedList
  9. 【HDU 2222】Keywords Search
  10. SharePoint2007安装图文详解三:安装SqlServer2005