当前位置: 代码网 > it编程>编程语言>Javascript > 使用@RequestParam接受JSON的字符串方式

使用@RequestParam接受JSON的字符串方式

2025年10月17日 Javascript 我要评论
@requestparam1.用来处理content-type: 为 application/x-www-form-urlencoded编码的内容。(http协议中,如果不指定content-type

@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

​总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com