Your location:Tech News>News>Script>Several methods Spring3 MVC parameter acquisition request summary

Latest News

Several methods Spring3 MVC parameter acquisition request summary

Author:fsadmin

Views:

  Spring3 MVC several methods parameter acquisition request

  First, the path through the acquisition parameters @PathVariabl

  @RequestMapping (value = "user / {id} / {name}", method = RequestMethod.GET)

  public String printMessage1 (@PathVariable String id, @ PathVariable String name, ModelMap model) {

  System.out.println (id);

  System.out.println (name);

  model.addAttribute ( "message", "111111");

  return "users";

  }

  For example, when accessing the user / 123 / lei path, performing the above method, wherein the parameter id = 123, name = lei

  Two, @ ModelAttribute form data obtaining FORM POST request

  JSP form below

  

  a:

  b:

  

  

  Java Pojo follows

  public class Pojo {

  private String a;

  private int b;

  }

  Java Controller as follows

  @RequestMapping (method = RequestMethod.POST)

  public String processSubmit (@ModelAttribute ( "pojo") Pojo pojo) {

  return "helloWorld";

  }

  Third, with direct access to HttpServletRequest

  @RequestMapping (method = RequestMethod.GET)

  public String get (HttpServletRequest request, HttpServletResponse response) {

  System.out.println (request.getParameter ( "a"));

  return "helloWorld";

  }

  Fourth, the request parameter binding with annotations @RequestParam

  @RequestParam annotation with a binding request to the parameter variable a.

  When a request parameter does not exist there is abnormality, by setting properties required = false solution,

  For example: @RequestParam (value = "a", required = false)

  Controller as follows

  @RequestMapping (value = "/ requestParam", method = RequestMethod.GET)

  public String setupForm (@RequestParam ( "a") String a, ModelMap model) {

  System.out.println (a);

  return "helloWorld";

  }

  That''s all for this article, I want to be helpful to learn, I hope you will support script Home.

  You may also be interested in the article: Detailed SpringMVC-- receiving a request parameters and mass participation to solve the dynamic page parameters learning SpringMVC- SpringMVC not receive a parameter value back problem after post request angular approach of spring mvc @PathVariable get request url in - how to get the request parameters Detailed axios springMVC not receive a request to send post parameters of solutions to quickly resolve the issue a comprehensive summary of the tutorial Spring SpringMVC @RequestBody request parameters with the map receives Spring MVC MVC request parameters received in response to the request parameters and the results of the global encryption and decryption Detailed

Recommend article

Relate article