SpringMVC @RequestParam和@RequestBody的区别
问题:@Requestbody 用的时候遇到400和415错误,因为请求格式不对。
@RequestBody
@RequestBody能把简单json结构参数转换成实体类,如下代码:
@RequestMapping(value = "/testUser", method = RequestMethod.POST)
public String testUser(@RequestBody User user){
System.out.print(user.getAge());
return "success";
}
参数为:
{"id":1,"user":"pkxutao","name":"name","age":18}
注意请求的content type要设置为application/json
- $.ajax({
- type:"POST",
- url : "adjectfkController/exportTemplate",
- cache:false,
- async:true,
- dataType:"json",
- contentType : 'application/json;charset=utf-8', //设置请求头信息
- data:jsonstr,
- success : function(result) {
- console.log(result);
- },
- error : function(result) {
- console.log("错误-----------------------------");
- }
- });
学习链接:https://blog.csdn.net/qq_27093465/article/details/50519444
SpringMVC @RequestParam和@RequestBody的区别的更多相关文章
- post传参params与body的区别(@RequestParam和@RequestBody的区别)
1.axios post请求 Content-Type默认为 application/x-www-form-urlencoded,我们传递参数的时,params里面的参数(简单的对象,通过 &quo ...
- springMVC中 @RequestParam和@RequestBody的区别
首先,不可以同时传进@RequestParam和@RequestBody,好像可以传进两个@RequestParam 如果不加@requestparam修饰,相当于 加上@requestparam且各 ...
- @RequestParam和@RequestBody的区别-------springMVC
https://blog.csdn.net/qq_27093465/article/details/50519444 @RequestParam 1,用来处理Content-Type: 为 appli ...
- @RequestParam 和@RequestBody 的区别?
@RequestParam用来接收: 1 用来处理简单的参数绑定 2 用来接收 Content-Type 是 application/x-www-form-urlencoded (这种格 式的数据 ...
- spring boot的@RequestParam和@RequestBody的区别
一.问题描述 由于项目是前后端分离,因此后台使用的是spring boot,做成微服务,只暴露接口.接口设计风格为restful的风格,在get请求下,后台接收参数的注解为RequestBody时会报 ...
- 灵活运用的@RequestParam和@RequestBody
最近在编写项目的过程中,老出现前后端传递参数格式不一致.不统一的问题,对于一个已经快工作一年的Java程序员来说,实属不合格,所以我就下来好好研究了一下@RequestParam和@RequestBo ...
- springMVC中@RequestParam和@RequestBody的作用
@RequestParam和@RequestBody是什么区别,估计很多人还是不太清楚, 因为一般用@ RequestParam就足够传入参数了,要说他们区别,就需要知道contentType是什么? ...
- @RequestParam、@RequestBody、@PathVariable区别和案例分析
一.前言 @RequestParam.@RequestBody.@PathVariable都是用于在Controller层接收前端传递的数据,他们之间的使用场景不太一样,今天来介绍一下!! 二.实体类 ...
- @RequestParam 和 @ PathVariable 的区别
@RequestParam 和 @ PathVariable 的区别http://localhost:8080/Springmvc/user/page.do?pageSize=3&pageNo ...
随机推荐
- compile FFMPEG under windows
这个文章应该算是中文版最好的了.但是还有一些需要修正. 特别是winsock2的处理 win10 msys2 vs2015 ffmpeg3.2.2 编译 这个英文版的才是最好的 Building ff ...
- php oracle数据库clob和nclob字段
php oracle数据库clob和nclob字段 nclob类型 1.nclob不能使用php的stream_get_contents来获取数据库的资源内容, 2.并且nclob只能使用to_cha ...
- 雷林鹏分享:C# 常量
C# 常量 常量是固定值,程序执行期间不会改变.常量可以是任何基本数据类型,比如整数常量.浮点常量.字符常量或者字符串常量,还有枚举常量. 常量可以被当作常规的变量,只是它们的值在定义后不能被修改. ...
- springboot---->javax.servlet.ServletException
springboot访问静态资源时发生以下异常: javax.servlet.ServletException: Circular view path [login]: would dispatch ...
- c++-pimer-plus-6th-chapter03
Chapter Review Having more than one integer type lets you choose the type that is best suited to a p ...
- 比较Class.getResource与Class.getClassLoader().getResource两种方式读取资源文件
/** * @author zhangboqing * @date 2018/7/10 */ public class FileDemo { public static void main(Strin ...
- 关于 android.net.conn.CONNECTIVITY_CHANGE 7.0之后取消
官方说法Declaring a broadcastreceiver for android.net.conn.CONNECTIVITY_CHANGE is deprecated for apps ta ...
- Pytorch的Reproducibility(可复现性)
对于Pytorch的结果复现,在不同版本的pytorch或者不同的硬件平台之间,不能够保证结果是完全一致的,即使在CPU和GPU上采用相同的随机数种子. 关于torch.backend.cudnn.b ...
- 【模板/经典题型】min-max容斥
一定注意容斥的时候-1的系数多加了1. 然后一种很常见的min-max容斥的策略就是以每个元素的出现时间作为权值. 最后一个出现的时间即为max,也就等价于全集出现的时间.
- selenium配置Chrome驱动
1.http://chromedriver.storage.googleapis.com/index.html chrome下载驱动地址 和对应的版本驱动,不用FQ 2.配置方法:如在e盘创建一个 ...