Spring Framwork5.0.5 (一)

下载Spring Framework 的 jar

http://repo.spring.io/release/org/springframework/spring/5.0.5.RELEASE/

Spring Framwork5.0.5 (一)_第1张图片
download spring framework jar

创建一个普通Java Project并引入Spring Framework jar

Spring Framwork5.0.5 (一)_第2张图片
package com.sheting.springframework.learning.demo01;

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

public class Student {

    private String name = "sheting";
    private int age;
    private Course course;
    private Teacher teacher;
    private List list;
    private List courses;
    private Map map;
    private Properties properties;
    private String gender = "男";

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

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

    public Course getCourse() {
        return course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }

    public Teacher getTeacher() {
        return teacher;
    }

    public void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

    public List getCourses() {
        return courses;
    }

    public void setCourses(List courses) {
        this.courses = courses;
    }

    public Map getMap() {
        return map;
    }

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

    public Properties getProperties() {
        return properties;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }
}
package com.sheting.springframework.learning.demo01;

public class Course {
    private String num;
    private String name;

    public String getNum() {
        return num;
    }

    public String getName() {
        return name;
    }

    public void setNum(String num) {
        this.num = num;
    }

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

}



    
        
        
        
        
        
        
        
            
        
        
        
            
                aa
                bb
                cc
            
        
        
            
                
            
        
        
        
            
                
                
                
            
        
        
        
            
                value-1
                value-2
            
        
        
        
    

    
        
        
    


package com.sheting.springframework.learning.demo01;

public class Teacher {
    private String name = "jiaoshi";

    public String getName() {
        return name;
    }

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

package com.sheting.springframework.learning.demo01;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {
    
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/demo.xml");
        Student bean = (Student)context.getBean("student");
        System.out.println(bean.getName());
        System.out.println(bean.getCourse().getNum());
        System.out.println(bean.getTeacher().getName());
        System.out.println(bean.getList().get(0));
        System.out.println(bean.getCourses().get(0).getName());
        System.out.println(bean.getMap().get("key1"));
        System.out.println(bean.getProperties().get("key-1"));
        System.out.println(bean.getGender());
        
    }
}

你可能感兴趣的:(Spring Framwork5.0.5 (一))