I am aware of @RequestMapping annotation which is used in Spring MVC based application.
I came across this piece of code:
@RequestMapping(method = POST, params = {"someParam"})
I understood the method
. However I don't know what params
means? Before this I never had seen anything which passed params to this annotation.
Can anyone help in understanding this?
In Spring MVC, the @RequestParam annotation is used to read the form data and bind it automatically to the parameter present in the provided method. So, it ignores the requirement of HttpServletRequest object to read the provided data.
Spring @RequestParam @RequestParam is a Spring annotation used to bind a web request parameter to a method parameter. It has the following optional elements: defaultValue - used as a fallback when the request parameter is not provided or has an empty value. name - name of the request parameter to bind to.
RequestMapping annotation is used to map web requests onto specific handler classes and/or handler methods. @RequestMapping can be applied to the controller class as well as methods.
To configure the mapping of web requests, we use the @RequestMapping annotation. The @RequestMapping annotation can be applied to class-level and/or method-level in a controller. The class-level annotation maps a specific request path or pattern onto a controller.
Your example means that the parameter someParam
must be present in the request. This is used to narrow down the matching methods for the given request.
See the documentation: RequestMapping#params
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With