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 ...
随机推荐
- layui 3种导航栏
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html ...
- Ubuntu 16.04 不能用inittab 设置 运行等级 runlevel
Ubuntu 用 systemd 了,所以就没有 runlevel 了. 对应的,是一个systemd targets. Mapping between runlevels and systemd t ...
- Arduino 开关控制小灯持续亮之具体思路
Arduino 开关控制小灯持续亮之具体思路 为什么写这篇文章: 我们用开关控制灯的亮灭的时候,希望只需要按一下按键就可以做到灯一直亮着.而在<Arduino魔法书>中——有弹性的按键这一 ...
- 20171104xlVBA各人各科进退
Sub 各班个人各科进步幅度() Dim dRank As Object Set dRank = CreateObject("Scripting.Dictionary") Dim ...
- eth
今天说下Centos的eth0:0这个虚拟端口,应为学到ifcofig eth0:0 IP,可以给一个网卡设置俩个IP地址,但是只是临时设置,然而我想永久设置,所以就在网找,最终找到的方法是 可以先复 ...
- SQL SERVER 一组数据按规律横着放置,少则补空,如人员按一进一出的规律,进出为一组,缺少的补null
假设一组数据:人员进出刷卡数据表[SwingCard] ID MenID Door 1 1 In 2 1 In 3 1 Out 4 1 In 5 1 Out 6 1 Out 想要变成如下:一进一出为一 ...
- 对偶图 并查集 BZOJ4423
题目链接 题目因为要根据上一次的输出结果来判断这次的输入,也就是要求我们强制在线,不能够把输入全部储存后处理 如果不要求强制在线,我们可以先把所以输入储存起来,从最后开始处理,把删边改成加边,如果在加 ...
- leetcode-algorithms-8 String to Integer (atoi)
leetcode-algorithms-8 String to Integer (atoi) Implement atoi which converts a string to an integer. ...
- python第三方库scrapy框架的安装
1.确认python和pip安装成功 2.安装win32py 提供win32api,下载地址:https://sourceforge.net/projects/pywin32/fil ...
- hdu-2865-polya+dp+矩阵+euler函数
Birthday Toy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...