spring6 为集合类型属性赋值 --引用集合类型的bean

1.准备工作:

Student.java

package bean.dimap;

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

public class Student {

    private String sid;
    private String sname;
//
    private Map map;
    //
    private List lessonList;

    public List getLessonList() {
        return lessonList;
    }

    public void setLessonList(List lessonList) {
        this.lessonList = lessonList;
    }

    public void run(){
        System.out.println("学生名:"+sname+" 学生id:"+sid);
        System.out.println(map);
        System.out.println(lessonList);
    }

    public String getSid() {
        return sid;
    }

    public void setSid(String sid) {
        this.sid = sid;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public Map getMap() {
        return map;
    }

    public void setMap(Map map) {
        this.map = map;
    }

    @Override
    public String toString() {
        return "Student{" +
                "sid='" + sid + '\'' +
                ", sname='" + sname + '\'' +
                ", map=" + map +
                ", lessonList=" + lessonList +
                '}';
    }
}

Teacher.java

package bean.dimap;

public class Teacher {
    private String tId;
    private String tName;

    @Override
    public String toString() {
        return "Teacher{" +
                "tId='" + tId + '\'' +
                ", tName='" + tName + '\'' +
                '}';
    }

    public String gettId() {
        return tId;
    }

    public void settId(String tId) {
        this.tId = tId;
    }

    public String gettName() {
        return tName;
    }

    public void settName(String tName) {
        this.tName = tName;
    }
}

2.xml配置:

beans-diRef.xml



 
    
        
        

        
        
    


    
        
        
    


    
        
            
                001
            
            
        
        
            
                002
            
            
        
    

    
        
    
    
        
    
    
        
        
    
    
        
        
    


3.前置知识:使用util:list、util:map标签必须引入相应的命名空间



4.控制台输出 

spring6 为集合类型属性赋值 --引用集合类型的bean_第1张图片

你可能感兴趣的:(Javaee,java,windows,服务器)