`

springmvc后台接收前台页面传递参数的方式

    博客分类:
  • web
阅读更多

前端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);
	}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics