spring-boot postman post请求遇到的坑

今天用postman调试接口,发现post请求进不去,一直报错

spring-boot postman post请求遇到的坑

get请求是可以的,我就纳闷了,难道是我写接口的姿势不对?

后来逐步分析问题,发现问题出在了请求头Header的Content-Type上,

application/x-www-form-urlencoded这个类型,就报错,

必须要改成application/json,

网上查下资料,大概懂了,

 

后台请求用@RequestBody的话,Content-Type就要设置为application/json,如果用@RequestParam的话,application/x-www-form-urlencoded这个格式也是可以的,就是前端数据以form方式提交

即application/x-www-form-urlencoded的时候传参方式如下

spring-boot postman post请求遇到的坑

spring-boot postman post请求遇到的坑

application/json的时候,传参方式就是正常的json格式

spring-boot postman post请求遇到的坑

spring-boot postman post请求遇到的坑