Spring中几种复杂类型的注入
2019-07-11 14:31
190 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_40903237/article/details/95476461
1、bean里面
[code]package com.yuanfeng.bean;/** * Created by yuanfeng on 2019/7/11 14:15 */ import java.io.Serializable; import java.util.*; /** *@ClassName Person *@Description T0D0 *@Author yuanfeng *@Date 2019/7/11 14:15 *@Version 1.0 **/ public class Person implements Serializable { private String[] hobby; private List<String> names;//list private Set<String> colors;//set private Map<String,String> map;//map private Properties properties; public List<String> getNames() { return names; } public void setNames(List<String> names) { this.names = names; } public Set<String> getColors() { return colors; } public void setColors(Set<String> colors) { this.colors = colors; } public Map<String, String> getMap() { return map; } public void setMap(Map<String, String> map) { this.map = map; } public Properties getProperties() { return properties; } public void setProperties(Properties properties) { this.properties = properties; } public void show(){ System.out.println("数组"+ Arrays.toString(hobby)); System.out.println("list"+ names); System.out.println("set"+ colors); System.out.println("map"+ map); System.out.println("properties"+ properties); } public String[] getHobby() { return hobby; } public void setHobby(String[] hobby) { this.hobby = hobby; } }2、applicationContext.xml
[code]<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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="p" class="com.yuanfeng.bean.Person"> <!--测试数组--> <property name="hobby"> <list> <value>学画画</value> <value>弹吉他</value> <value>学游泳</value> </list> </property> <!--测试list集合--> <property name="names"> <list> <value>中国</value> <value>小日本</value> <value>美国</value> </list> </property> <!--测试set集合--> <property name="colors"> <set> <value>笑傲江湖</value> <value>招摇</value> <value>村上村塾</value> </set> </property> <!--测试map集合--> <property name="map"> <map> <entry key="zjl"><value>周杰伦</value></entry> <entry key="cyx"><value>陈奕迅</value></entry> <entry key="zxy"><value>张学友</value></entry> </map> </property> <!--测试properties--> <property name="properties"> <map> <entry key="username"><value>zhoujielun</value></entry> <entry key="password"><value>1234</value></entry> <entry key="driverClass"><value>com.mysql.jdbc.Driver</value></entry> </map> </property> </bean> </beans>
相关文章推荐
- Spring学习之注入方式(简单类型和复杂类型)
- Spring中属性注入的几种方式以及复杂属性的注入
- spring笔记--依赖注入之针对不同类型变量的几种注入方式
- Spring中属性注入的几种方式以及复杂属性的注入
- 【Spring实战】—— 7 复杂集合类型的注入
- 【Spring实战】—— 7 复杂集合类型的注入
- Spring注入复杂类型属性
- Spring属性注入【三】 复杂类型注入
- Spring中属性注入的几种方式以及复杂属性的注入详解
- Spring注入复杂类型属性
- Spring注入复杂类型属性
- Spring_Spring_教程8_注入_复杂类型的注入
- Spring中复杂类型注入
- SSH与SSM学习之Spring08——Spring属性注入之复杂类型注入
- spring复杂类型属性注入
- Spring(8)注入复杂类型属性
- JAVA框架spring复杂类型注入
- Spring的几种注入类型
- spring使用set方法注入的常见类型写法
- 如何让xdoclet 的spring 标签支持java.util.Map类型属性的注入