位置:首页 > > SpringMVC自动装箱

SpringMVC自动装箱

1.编写一个Person实体类
package test.SpringMVC.model;
 
public class Person {
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    private String name;
    private int age;
     
}
2.在Controller里编写方法
//boxing automatically
@RequestMapping("/person1")
public String toPerson(Person p){
    System.out.println(p.getName()+" "+p.getAge());
    return "hello";
}