spring的pojo类属性的注入

spring的pojo类属性的注入_第1张图片

1、写一个类,它有各种类型的属性,将属性的get,set方法补全:

package com.sky.spring.sysmanage.entity;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * pojo对象常见属性的注入
 * @author Administrator
 *
 */
public class User {

    private String strValue;
    private int intValue;
    private List listValue;
    private Set setValue;
    private String[] strArrayValue;
    private Map mapValue;

    public String getStrValue() {
        return strValue;
    }
    public void setStrValue(String strValue) {
        this.strValue = strValue;
    }
    public int getIntValue() {
        return intValue;
    }
    public void setIntValue(int intValue) {
        this.intValue = intValue;
    }
    public List getListValue() {
        return listValue;
    }
    public void setListValue(List listValue) {
        this.listValue = listValue;
    }
    public Set getSetValue() {
        return setValue;
    }
    public void setSetValue(Set setValue) {
        this.setValue = setValue;
    }
    public String[] getStrArrayValue() {
        return strArrayValue;
    }
    public void setStrArrayValue(String[] strArrayValue) {
        this.strArrayValue = strArrayValue;
    }
    public Map getMapValue() {
        return mapValue;
    }
    public void setMapValue(Map mapValue) {
        this.mapValue = mapValue;
    }




}

2、在spring容易中实现该类的属性注入

<bean class="com.sky.spring.sysmanage.entity.User" id="user">
        <property name="strValue" value="this is stringVal">
        property>
        <property name="intValue" value="123">
        property>

        <property name="listValue">
            <list>
                <value>listValue1value>
                <value>listValue2value>
            list>
        property>

         <property name="setValue">
                <set>
                    <value>set1value>
                    <value>set2value>
                    <value>set3value>
                set>
         property>
         <property name="strArrayValue">
            <list>
                <value>strArray1value>
                <value>strArray1value>
                <value>strArray1value>
            list>
         property>
         <property name="mapValue">
            <map>
                <entry key="key1" value= "map1">entry>
                <entry key="key2" value= "map2">entry>
                <entry key="key3" value= "map3">entry>
            map>
         property>     
   bean>      
bean>

spring的pojo类属性的注入_第2张图片

你可能感兴趣的:(spring)