1,使用HttpServletRequest获取
1.1后台方法
@RequestMapping(value="/login",method = RequestMethod.POST)
public String login(HttpServletRequest request) {
if(userService.selectUser(request.getParameter("username"),request.getParameter("password"))!=null)
{
return "index";
}
else
return "login";
}
1.2前台表单的name属性要和后台参数名保持一致
<form action="mavenTest/user/login" method="post">
<input type="text" name="username" placeholder="Username...">
<input type="password" name="password" placeholder="Password...">
<button type="submit" class="btn">Sign in!</button>
</form>
2.自动注入bean属性
2.1后台方法
@RequestMapping(value="/login",method = RequestMethod.POST)
public String login(User user) {
if(userService.selectUser(user.getUsername(),user.getPassword())!=null){
return "index";
}
else
return "login";
}
2.2前台表单的name属性要和类的参数名保持一致,并且要有相应的get和set方法
user类
public class User implements Serializable{
private int id;
private String username;
private String password;
private int age;
<form action="mavenTest/user/login" method="post">
<input type="text" name="username" placeholder="Username...">
<input type="password" name="password" placeholder="Password...">
<button type="submit" class="btn">Sign in!</button>
</form>