【Spring】DI依赖注入实例 set注入

一、创建环境

在IDEA下使用快捷键 alt+insert 召唤出构造器 可以设置诸多方法

 

创建学生类 其中有各种类型字段

 

 

 Address类代码

 

 

import java.util.List;
import java.util.*;

/**
 * @Description: 学生类 拥有复杂类型的字段
 * @Author: cckong
 * @Date: 2021/2/3
 */
public class Student {
    private String name;
    private Address address;

    private String[] books;
    private List<String> hobbies;

    private Map<String, String> card;
    private Set<String> game;

    private Properties infor;
    private String wife;

    public String getName() {
        return name;
    }

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

    public Address getAddress() {
        return address;
    }

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

    public String[] getBooks() {
        return books;
    }

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

    public List<String> getHobbies() {
        return hobbies;
    }

    public void setHobbies(List<String> hobbies) {
        this.hobbies = hobbies;
    }

    public Map<String, String> getCard() {
        return card;
    }

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

    public Set<String> getGame() {
        return game;
    }

    public void setGame(Set<String> game) {
        this.game = game;
    }

    public Properties getInfor() {
        return infor;
    }

    public void setInfor(Properties infor) {
        this.infor = infor;
    }

    public String getWife() {
        return wife;
    }

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

    @Override
    public String toString() {
        return "Student{" +"\n"+
                "name='" + name + '\'' +"\n"+
                ", address=" + address.toString() +"\n"+
                ", books=" + Arrays.toString(books) +"\n"+
                ", hobbies=" + hobbies +"\n"+
                ", card=" + card +"\n"+
                ", game=" + game +"\n"+
                ", infor=" + infor +"\n"+
                ", wife='" + wife + '\'' +"\n"+
                '}';
    }
}

 

 

二、配置文件注入

 

 

 

 

 

 

 

 

三、检验赋值成果

 

posted @ 2021-02-03 23:42  枫叶像思念  阅读(136)  评论(0编辑  收藏  举报