命名空间装配

2019-11-17  本文已影响0人  二狗不是狗

待装配bean

public class Role {
    private Long id;
    private String roleName;
    private String note;
}

public class User {
    private Long id;
    private String userName;
    private String note;
}

public class UserRoleAssembly {
    private Long id;
    private List<Role> list;
    private Map<Role, User> map;
    private Set<Role> set;
}

 /**** setter and getter函数 ****/

普通装配

<bean id="userRoleAssembly" class="com.ssm.UserRoleAssembly">
        <property name="id" value="1"/>
        <property name="list">
            <list>
                <ref bean="role1"/>
                <ref bean="role2"/>
            </list>
        </property>
        <property name="map">
            <map>
                <entry key-ref="role1" value-ref="user1"/>
                <entry key-ref="role2" value-ref="user2"/>
            </map>
        </property>
        <property name="set">
            <set>
                <ref bean="role1"/>
                <ref bean="role2"/>
            </set>
        </property>
</bean>

命名空间装配

<bean id="role1" class="com.ssm..Role" c:_0="1" c:_1="role_name_1" c:_2="role_note_1"/>
<bean id="role2" class="com.ssm.Role" p:id="2" p:roleName="role_name_2" p:note="role_note_2"/>
<util:list id="list">
    <ref bean="role1"/>
    <ref bean="role2"/>
</util:list>
<util:map id="map">
    <entry key-ref="role1" value-ref="user1"/>
    <entry key-ref="role2" value-ref="user2"/>
</util:map>
<util:set id="set">
    <ref bean="role1"/>
    <ref bean="role2"/>
</util:set>
<bean id="userRoleAssembly" class="com.ssm.UserRoleAssembly" p:id="1" p:list-ref="list" p:map-ref="map" p:set-ref="set"/>

常用的util-工具类


image.png
上一篇下一篇

猜你喜欢

热点阅读