In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how springboot receives application/x-www-form-urlencoded type requests, which can be used for reference by interested friends. I hope you will gain a lot after reading this article. Let's take a look at it.
Request data
Id:1
RoleName:admin
RoleDes: with admin permission
Several processing methods of Controller
First kind
@ ApiOperation ("query user") @ PostMapping ("/ detailByParam") public void detailByParam (@ RequestParam (value = "id") Integer id,@RequestParam (value = "roleName") String roleName,@RequestParam (value = "roleDes") String roleDes) {System.out.println ("> id=" + id+ ", roleName=" + roleName+ ", roleDes=" + roleDes);}
Print information:
> id=1,roleName=admin,roleDes= has admin permission
The second kind
@ ApiOperation ("query user") @ PostMapping ("/ detailByParam") public void detailByParam (@ RequestParam Map params) {System.out.println ("> id=" + params.get ("id") + ", roleName=" + params.get ("roleName") + ", roleDes=" + params.get ("roleDes");}
Print information:
> id=1,roleName=admin,roleDes= has admin permission
The third kind
@ ApiOperation ("query user") @ PostMapping ("/ detailByParam") public void detailByParam (@ RequestBody String params) {System.out.println ("> >" + params);}
Print information:
> id=1&roleName=admin&roleDes=%E6%8B%A5%E6%9C%89admin%E6%9D%83%E9%99%90
The fourth kind
@ ApiOperation ("query user") @ PostMapping ("/ detailByParam") public void detailByParam (@ RequestBody GetRoleParam getRoleParam) {System.out.println ("> >" + getRoleParam);}
Return an error message:
"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported"
SpringMVC application/x-www-form-urlencoded receiving mode test
Premise: for ease of understanding
All classes use @ Controller instead of RestController
Method uses @ RequestMapping
All postman requests are as follows
1. No comments are added before the parameter
1.1 request
Success!
1.2 map
Failure!
1.3 pojo
Success!
two。 Add @ RequestParam before the parameter
2.1 request
Failure!
2.2 map
Success!
2.3 poji
Failure!
3. Add @ RequestBody before the parameter
3.1 request
Failure!
3.2 map
Failure!
3.3 pojo
Request
Map
Pojo
No comments
√
×
√
@ RequestParam
×
√
×
@ RequestBody
×
×
×
Thank you for reading this article carefully. I hope the article "how to receive application/x-www-form-urlencoded requests from springboot" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.