Spring MVC 3 表单提交时,自动将各输入字段封装成实体Bean

  
Username: userName" />



@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	private IUserService userService;
	
	@RequestMapping(value="/gologin")
	public String goLogin(){
		return "user/login";
		
	}
	@RequestMapping(value="/login",method=RequestMethod.POST)
	public String login(User user,Model model){
		User u = userService.login(user);
		if(u == null) {
			model.addAttribute("message", "用户不存在,请注册");
			return "user/login";
		}else {
			model.addAttribute("userSessionInfo", u);
			return "welcome";
		}
	}
	

User 类中要有 private String userName;       //用户名  属性,并且提供setter/getter方法






你可能感兴趣的:(Spring MVC 3 表单提交时,自动将各输入字段封装成实体Bean)