我想从输入表单中获取数据(登录data->密码+用户名)并将其保存到bean中。然后,我想把这个bean和数据放在里面,并得到一个得到的回报。
我宣布了一个班级:
public class Login {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
getrequest如下:
@RequestMapping(value = "/log",method = RequestMethod.GET)
public String addPersonLogin( Model model,HttpServletRequest request) {
//take the bean here
}
任何人都可以告诉我如何创建jsp以及如何将bean处理为addPersonLogin?
答案 0 :(得分:1)
你可以这样做(使用@ModelAttribute):
@InitBinder
public void initBinder(WebDataBinder binder) {
// You can register your validator for bean Login here
}
@RequestMapping(value = "/log",method = RequestMethod.GET)
public String addPersonLogin(@ModelAttribute Login login, HttpServletRequest request) {
// To make it work your form fields should have names equals to bean fields names
login.getUserName();
login.getPassword();
}