This article is a mirror article of machine translation, please click here to jump to the original article.

View: 12871|Reply: 1

[Source] The difference between annotations in springMVC @RequestParam and @PathVariable

[Copy link]
Posted on 9/5/2018 5:28:23 PM | | |
@PathVariable bind the value of the URI template variable

@PathVariable is used to get dynamic parameters in the request URL

@PathVariable used to map template variables in the request URL to parameters of the feature handling method. Configure a relationship between the URL and the method@RequestMapping ("item/{itemId}")

There are two main ways to obtain parameters in the Spring MVC background control layer:


One is request.getParameter("name"), and the other is to get it directly with an annotation @RequestParam

This is mainly about this annotation @RequestParam

Next, let's take a look at the main parameters of @RequestParam annotations:

value: parameter name, that is, the name of the request parameter entered into the parameter, such as username means that the value of the parameter named username in the requested parameter area will be passed;

required: whether it is necessary, the default is true, which means that there must be corresponding parameters in the request, otherwise a 404 error code will be reported;

defaultValue: The default value that indicates the default value if there is no parameter with the same name in the request, for example:

public List<EasyUITreeNode> getItemTreeNode(@RequestParam(value="id",defaultValue="0")long parentId)







Previous:Mybatis automatically generates an Xml file, and XXX will be generated by default for field types such as text...
Next:Share an API development framework
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com