zoukankan      html  css  js  c++  java
  • spring list、map注入

    <?xml version="1.0" encoding="utf-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:tx="http://www.springframework.org/schema/tx"
            xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    
    <bean id="department" class="com.hsp.collection.Department">
    <property name="name" value="财务部"/>
    
    <!-- 给数组注入值 -->
    <property name="empName">
        <list>
            <value>a</value>
            <value>b</value>
            <value>c</value>
        </list>
    </property>
    
    <!-- 给list注入值 list 中可以有相当的对象 -->
    <property name="empList">
        <list>
            <ref bean="emp2" />
            <ref bean="emp1"/>
            <ref bean="emp1"/>
            <ref bean="emp1"/>
            <ref bean="emp1"/>
            <ref bean="emp1"/>
            <ref bean="emp1"/>
        </list>
    </property>
    
    <!-- 给set注入值 set不能有相同的对象 -->
    <property name="empsets">
        <set>
            <ref bean="emp1" />
            <ref bean="emp2"/>
            <ref bean="emp2"/>
            <ref bean="emp2"/>
            <ref bean="emp2"/>
        </set>
    </property>
    
    <!-- 给map注入值 map只有key不一样,就可以装配value -->
    <property name="empMaps">
        <map>
            <entry key="11" value-ref="emp1" /> 
            <entry key="22" value-ref="emp2"/>
            <entry key="22" value-ref="emp1"/>
        </map>
    </property>
    
    <!-- 给属性集合配置 -->
    <property name="pp">
        <props>
            <prop key="pp1">abcd</prop>
            <prop key="pp2">hello</prop>
        </props>
    </property>
    </bean>
    
    <bean id="emp1" class="com.hsp.collection.Employee">
        <property name="name" value="北京"/>
        <property name="id" value="1"/>
    </bean>
    <bean id="emp2" class="com.hsp.collection.Employee">
        <property name="name" value="天津"/>
        <property name="id" value="2"/>
    </bean>
    
    </beans>
  • 相关阅读:
    TRUNCATE TABLE 删除表中的所有行,而不记录单个行删除操作
    血腥!实况转播SQL注入全过程,让你知道危害有多大。
    DB2隔离级别设置
    使用解释工具分析SQL语句
    DB2的七种武器
    db2精华文档和论坛链接
    “饮水机”:形象比喻 深入浅出理解RAID
    DB2 数据库恢复测试
    IBM DB2 日常维护汇总
    镜像分割与高可用性灾难恢复
  • 原文地址:https://www.cnblogs.com/qiutianyou/p/6242633.html
Copyright © 2011-2022 走看看