首先看一下结果:
在首页main-form设置Student Form链接
进入student/showForm编辑姓名,由于建立了student类保存和获取姓、名,所以在studentController中的建立student对象,使用@modelAttribute将编辑文本框中的内容和(student)theStudent.lastName,theStudent.firstName绑定,再通过这个StudentController将student-confirmation传到页面的时候显示出来。
下面是代码:
Student 类
public class Student {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Student() {
}
}
StudentController
@Controller
@RequestMapping("/student")
public class StudentController {
@RequestMapping("/showForm")
public String showForm(Model theModel) {
//create a student object
Student theStudent = new Student();
//add student object to the model
theModel.addAttribute("student",theStudent);
return "student-form&