springMVC初体验

1、新建javabean

 

package logo.module;

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

public class Student {
        private Integer id;
        private String name;
        private List dream;
        private Map score;
        private boolean graduation;
    
        public Student(Integer id, String name, List dream,
                Map score, boolean graduation) {
            this.id = id;
            this.name = name;
            this.dream = dream;
            this.score = score;
            this.graduation = graduation;
        }
                                                                                                                                                                              
        @Override
        public String toString() {
            return "Student [id=" + id + ", name=" + name + ", dream=" + dream
                    + ", score=" + score + ", graduation=" + graduation + "]";
        }
                 

    public Student() {
        super();
        // TODO Auto-generated constructor stub
    }

    
    
    
    

}

2、src目录下创建applicationContext.xml,构造方法

 

springMVC初体验_第1张图片

applicationContext.xml配置如下


    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
   
   
   
   
       
            soldier
            scientist
            pilot
       

   

   
       
           
           
       

   

   

3、驱动执行

 

package logo.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import logo.module.Student;

public class Run {
public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    Student student =(Student) context.getBean("me");
    System.out.println(student);
    
}
}
4、运行结果

 

你可能感兴趣的:(spring)