我正在学习 Spring MVC,我到处都在做一个基本的控制器来查看数据绑定,但我没有尝试过任何工作。我可以将视图发布绑定回控制器,并且可以在那里看到带有属性的 pojo,但是每当我尝试将该对象添加到模型时,我什么也得不到。这是我到目前为止所拥有的:
控制器
@Controller
public class HomeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Model model) {
model.addAttribute(new Person());
return "home";
}
@RequestMapping(value="/about", method=RequestMethod.POST)
public void about(Person person, Model model)
{
model.addAttribute("person", person);
}
}
我要绑定的班级
public class Person {
private String _firstName;
private String _lastName;
private Date _Birthday;
//Set
public void setFirstName(String FirstName){this._firstName = FirstName; }
public void setLastName(String LastName){this._lastName= LastName; }
public void setBirthDate(Date BirthDate){ this._Birthday = BirthDate;}
//get
public String getFirstName(){return _firstName;}
public String getLastName(){return _lastName;}
public Date getBirthDate(){return _Birthday;}
}
视图 - 控制器到表单!在职的
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<html>
</head>
<body>
FirstName: ${model.person.getFirstName}
LastName: ${model.person.getLastName}
</body>
</html>
我可以或需要做什么才能使其绑定?