Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does springboot receive requests of type application/x-www-form-urlencoded

2025-03-16 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report