springmvc后台接收前台页面传递参数的方式
程序员文章站
2022-07-15 11:10:02
...
前端form传递username和password两个参数,后端的接收方式可以有一下几种方式:
@RequestMapping("/jsp/login/login.do")
public ModelAndView login(String username,String password){
ModelMap map = new ModelMap();
map.put("loginUser", username);
return new ModelAndView("/jsp/login/hello",map);
}
@RequestMapping("/jsp/login/login.do")
public ModelAndView login(String username){
ModelMap map = new ModelMap();
map.put("loginUser", username);
return new ModelAndView("/jsp/login/hello",map);
}
@RequestMapping("/jsp/login/login.do")
public ModelAndView login(User user){
ModelMap map = new ModelMap();
map.put("loginUser", user.getUsername());
return new ModelAndView("/jsp/login/hello",map);
}
@RequestMapping("/jsp/login/login.do")
public ModelAndView login(HttpServletRequest request){
String username = request.getParameter("username");
ModelMap map = new ModelMap();
map.put("loginUser", username);
return new ModelAndView("/jsp/login/hello",map);
}
@RequestMapping("/jsp/login/login.do")
public String login(HttpServletRequest request ,Model model){
String username = request.getParameter("username");
model.addAttribute("loginUser", username);
return "/jsp/login/hello";
}
@RequestMapping("/jsp/login/login.do")
public ModelAndView login(HttpServletRequest request,ModelMap map){
String username = request.getParameter("username");
map.put("loginUser", username);
return new ModelAndView("/jsp/login/hello",map);
}
上一篇: 第一个只出现一次字符的位置 牛客网 剑指Offer
下一篇: SpringMvc 入门 (注解)