Home >Java >javaTutorial >The difference between requestbody and requestparam
##@RequestParam -www-form-urlencoded encoded content. (In the Http protocol, if Content-Type is not specified, the parameter passed by default is the application/x-www-form-urlencoded type)
@RequestBody•In the GET request, because there is no HttpEntity, @RequestBody does not apply.
•In POST requests, the parameters passed through HttpEntity must declare the data type Content-Type in the request header. SpringMVC parses the data in HttpEntity by using the HttpMessageConverters configured with HandlerAdapter , and then bind to the corresponding bean.Summary
•In GET requests, @RequestBody cannot be used.
•In POST requests, you can use @RequestBody and @RequestParam, but if you use @RequestBody, the configuration of parameter conversion must be unified.
For example, in the HttpMessageConverters processing stack configured in SpringMVC, specify the json conversion format. For example, if Date is converted to 'yyyy-MM-dd', then the fields contained in the parameter receiving object If it is a Date type, the client can only pass the year, month and day format, but not the hours, minutes and seconds. Because different interfaces, their parameters may have different format requirements for time parameters, so doing so will make the client calling colleagues a little confused about the format of the parameters, so the scalability is not high.
For more Java-related technical articles, please visit the
java tutorial column to learn!
The above is the detailed content of The difference between requestbody and requestparam. For more information, please follow other related articles on the PHP Chinese website!