欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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