Spring04:注入复杂类型数据(仅供查询)

这是当时看某up主视频记的东西,太多,也不整理了。用的时候肯定能在里面找到自己要的足矣。

package com.xxx;

public class Address {
    private String address;

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}
package com.xxx;

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

public class Satudent {
    private String name;
    private Address address;
    private String[] books;
    private List<String> hobbys;
    private Map<String,String> card;
    private Set<String> games;
    private String wife;
    private Properties info;

    public void setName(String name) {
        this.name = name;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public void setBooks(String[] books) {
        this.books = books;
    }

    public void setHobbys(List<String> hobbys) {
        this.hobbys = hobbys;
    }

    public void setCard(Map<String, String> card) {
        this.card = card;
    }

    public void setGames(Set<String> games) {
        this.games = games;
    }

    public void setWife(String wife) {
        this.wife = wife;
    }

    public void setInfo(Properties info) {
        this.info = info;
    }

    public void show(){
        System.out.println("name="+ name
                + ",address="+ address.getAddress()
                + ",books="
        );
        for (String book:books){
            System.out.print("<<"+book+">>\t");
        }
        System.out.println("\n爱好:"+hobbys);
        System.out.println("card:"+card);
        System.out.println("games:"+games);
        System.out.println("wife:"+wife);
        System.out.println("info:"+info);
    }
}
<?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="student" class="com.xxx.Student">
        <property name="name" value="小明同学"></property>
        <property name="address" ref="addr"></property>
        <property name="books">
            <array>
                <value>西游记</value>
                <value>红楼梦</value>
            </array>
        </property>
        
        <property name="hobbys">
            <list>
                <value>听歌</value>
                <value>看电影</value>
            </list>
        </property>
        
        <property name="card">
            <map>
                <entry key="中国邮政" value="123"></entry>
                <entry key="中国建设" value = "456"></entry>
            </map>
        </property>

        <property name="games">
            <set>
                <value>LOL</value>
                <value>BOB</value>
            </set>
        </property>

        <property name="info">
            <props>
                <prop key="学号">20091812</prop>
                <prop key="性别"></prop>
                <prop key="姓名">小明</prop>
            </props>
        </property>

        <property name="wife"><null></null></property>
    </bean>

    <bean id="addr" class="com.xxx.Address">
        <property name = "address" value = "北京市"></property>
    </bean>

</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值