SpringBoot 出现 Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported

前端请求传Json对象的字符串则后端使用@RequestBody。
前端请求传Json对象则后端使用@RequestParam;

当前端请求的Content-Type是Json时,可以用@RequestBody这个注解来解决。@RequestParam 底层是通过request.getParameter方式获得参数的,换句话说,@RequestParam 和request.getParameter是同一回事。因为使用request.getParameter()方式获取参数,可以处理get 方式中queryString的值,也可以处理post方式中 body data的值。所以,@RequestParam可以处理get 方式中queryString的值,也可以处理post方式中 body data的值。@RequestParam用来处理Content-Type: 为 application/x-www-form-urlencoded编码的内容,提交方式GET、POST。

@RequestBody接受的是一个json对象的字符串,而不是Json对象,在请求时往往都是Json对象,用JSON.stringify(data)的方式就能将对象变成json字符串。

原文链接:https://blog.csdn.net/feiyst/java/article/details/88431621

猜你喜欢

转载自blog.csdn.net/m0_52936310/article/details/113059460