• spring4 注入参数


    <?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="people1" class="com.java1234.entity.People">
            <property name="id" value="1"></property>
            <property name="name" value="张三"></property>
            <property name="age" value="11"></property>
        </bean>
        <!--注入bean -->
        <bean id="dog1" class="com.java1234.entity.Dog">
            <property name="name" value="Jack"></property>
        </bean>
        
        <bean id="people2" class="com.java1234.entity.People">
            <property name="id" value="1"></property>
            <property name="name" value="张三"></property>
            <property name="age" value="11"></property>
            <property name="dog" ref="dog1"></property>
        </bean>
        <!--内部bean -->
        <bean id="people3" class="com.java1234.entity.People">
            <property name="id" value="1"></property>
            <property name="name" value="张三"></property>
            <property name="age" value="11"></property>
            <property name="dog">
                <bean class="com.java1234.entity.Dog">
                    <property name="name" value="Tom"></property>
                </bean>
            </property>
        </bean>
        <!-- null值-->
        <bean id="people4" class="com.java1234.entity.People">
            <property name="id" value="1"></property>
            <property name="name" value="张三"></property>
            <property name="age" value="11"></property>
            <property name="dog">
                <null></null>
            </property>
        </bean>
        <!-- 级联属性-->
        <!-- <bean id="people5" class="com.java1234.entity.People">
            <property name="id" value="1"></property>
            <property name="name" value="张三"></property>
            <property name="age" value="11"></property>
            <property name="dog.name" value="Jack2"></property>
        </bean> -->
        <!-- 集合属性-->
        <bean id="people6" class="com.java1234.entity.People">
            <property name="id" value="1"></property>
            <property name="name" value="张三"></property>
            <property name="age" value="11"></property>
            <property name="dog" ref="dog1"></property>
            <property name="hobbies">
                <list>
                    <value>唱歌</value>
                    <value>跳舞</value>
                </list>
            </property>
            <property name="loves">  <!--set是不可以重复的 -->
                <set>
                    <value>唱歌2</value>
                    <value>跳舞2</value>
                </set>
            </property>
            <property name="works">  <!--键值对 -->
                <map>
                    <entry>
                        <key><value>上午</value></key>
                        <value>写代码</value>
                    </entry>
                    <entry>
                        <key><value>下午</value></key>
                        <value>测试代码</value>
                    </entry>
                </map>
            </property>
            <property name="addresses"> <!--属性 一般用于系统配置 -->
                <props>
                    <prop key="address1">aaaaa</prop>
                    <prop key="address2">bbbbb</prop>
                </props>
            </property>
        </bean>
        
    </beans>

    private List<String> hobbies=new ArrayList<String>();
    private Set<String> loves=new HashSet<String>();
    private Map<String,String> works=new HashMap<String,String>();
    private Properties addresses=new Properties();

  • 相关阅读:
    Ubuntu 12.04下PostgreSQL-9.1安装与配置详解(在线安装) [转]
    network error:software caused connection abort
    MySQL数据库SQL修改数据规范
    常见的动物单词汇总
    PHP观察者模式
    PHP单例模式
    PHP工厂模式
    PHP面试准备
    Let Encrypt延期(转自虞大胆的叽叽喳喳)
    全球最昂贵的域名和国内著名的域名交易
  • 原文地址:https://www.cnblogs.com/rogge7/p/7018362.html
Copyright © 2020-2023  润新知