There are three ways to obtain the value transmitted from the front desk in the previous controller method:
1. Through HttpServletRequest:
@RequestMapping(value="/index1")public String helloaction1(HttpServletRequest request){ System.out.println(request.getParameter("nnn")); //Get the value of the element with the front-end name nnn return "index";}2. Obtain the parameter name:
@RequestMapping(value="/index1")public String helloaction1(String nnn){ //The name here must be consistent with the front-end element name to obtain System.out.println(nnn); return "index";}3. Obtained through @RequestParam annotation:
@RequestMapping(value="/index")public String helloaction(@RequestParam(value="nnn", required=false)String nnn1, Model model){ //nnn should be consistent with the front-end, which can be understood here as the alias for parameter nnn1 System.out.println(nnn1); model.addAttribute("hello", "This is the value passed by action: "+nnn1); return "index";}SpringMvc can also obtain various properties of vo by taking vo as a parameter:
@RequestMapping(value="/index2")public String helloaction2(User user){ System.out.println(user.getAccount()); System.out.println(user.getPassword()); return "index";}When using objects to obtain data, be careful that the element name attribute of the front-end page must be consistent with the names of each attribute of vo
The above example of the value transmitted by the SpringMVC front desk is all the content shared by the editor. I hope it can give you a reference and I hope you can support Wulin.com more.