@requestparam
1.用来处理content-type: 为 application/x-www-form-urlencoded编码的内容。
(http协议中,如果不指定content-type,则默认传递的参数就是application/x-www-form-urlencoded类型)
@requestparam可以接受简单类型的属性,也可以接受对象类型。
2.用来处理 multipart/form-data (表单上传的)
如何使用@requestparam 接受json的字符串
- 前端代码
const message = {
"data": {
"userinfo": "2804951212",
"offerid": offerid,
"action": "distribution",
"categorynav": categorynav
},
"gmtborn": time,
"msgid": time,
"type": "product_collection",
"userinfo": "chrome"
};
$.ajax({
contenttype :'application/x-www-form-urlencoded',
type:'post',
url: baseurl+'/ali-receive',
data:"message="+json.stringify(message)
});
- 后端代码
@postmapping("/ali-receive")
public void alireceive(@requestparam("message") string message) {
receivelog receivelog = json.parseobject(message, receivelog.class);
}
@requestbody
一般用来处理 content-type: 为application/json
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论