@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView myMethod(HttpServletRequest request,
HttpServletResponse response,
//@RequestParam("username")String username, @RequestParam("password")String password
String username,String password,//如果和前台的一样一样简写成这样
ModelMap modelMap) throws Exception {
username = new String(username.getBytes("iso8859-1"),"UTF-8");//编码问题 (服务器一帮都是iso的)
System.out.println(username+":"+password);
modelMap.put("loginUser", username);
modelMap.put("msg", "I'm in session");
return new ModelAndView("/view/hello", modelMap);
}
这里是一个方法,springMVC中参数可以直接现在方法的参数列表中,如果是对象属性的话也可以直接使用对象例如(User user,...)
刚才的方法对应的前台: