Spring Cloud (12) | Spring Cloud Zuul网关调用微服务,request请求参数是application/json
发布日期:2021-06-30 12:19:25 浏览次数:2 分类:技术文章

本文共 621 字,大约阅读时间需要 2 分钟。

在做Spring Cloud Zuul网关调用微服务的时候,request请求参数是以&连接的text/html形式,这样的数据不是特别好处理,其实可以通过split截取,但是如果参数里面包含”&”,就很麻烦,所以接下来通过下面的步骤来解决:

  1. 前端请求传输数据需要是json的形式, dataType: “json”, contentType : “application/json; charset=utf-8”,data: JSON.stringify(req)这几个
$.ajax({        type: "POST",        url: "xxx/create",        dataType: "json",        contentType : "application/json; charset=utf-8",        data: JSON.stringify(req),        success: function (data) {        }

2.在微服务中参数增加@RequestBody

@RequestMapping(value = "/create", method = RequestMethod.POST)    public void create(@RequestBody String info) {    }

这样info得到的就是json格式

更多系列文章推荐:

转载地址:https://java-basketball.blog.csdn.net/article/details/78683684 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Mac Notes备忘录崩溃打不开:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '
下一篇:Spring Cloud (6) | spring cloud zuul 跨域问题No 'Access-Control-Allow-Origin' header

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月27日 02时40分36秒