好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

FeignClient实现接口调用方式(不同参数形式)

FeignClient接口调用

无参 字符串参数 对象参数

拟定客户端调用服务端接口,直接放代码啦,参考格式即可。

1、无参

服务端方法:

?

1

2

3

4

5

6

7

8

    /**

      * 测试,获取简单文本

      */

    @GetMapping ( "/info" )

    public String info()

    {

        return "零零" ;

    }

客户端方法:

?

1

2

3

4

5

    /**

      * 接口测试

      */

    @GetMapping (value = "/info" )

    public String getInfo();

2、字符串参数

服务端方法:

?

1

2

3

4

5

@ResponseBody

    @PostMapping (value = "/test" )

    public String test(String s) {

        return s;

    }

客户端方法:

?

1

2

    @RequestMapping (value = "/test" , method = RequestMethod.POST)

    String test( @RequestParam (value = "s" ) String s);

3、对象参数

服务端方法:

?

1

2

3

4

5

    @PostMapping (value = "/company/list" )

    public List<CruiseCompInfo> companyList( @RequestBody CruiseCompInfo cruiseCompInfo)

    {

        return cruiseCompInfoService.selectCruiseCompInfoList(cruiseCompInfo);

    }

客户端方法:

?

1

2

   @RequestMapping (value = "/company/list" , method = RequestMethod.POST)

    public List<CruiseCompInfo> companyList( @RequestBody CruiseCompInfo cruiseCompInfo);

feign接口参数遇到的bug

服务接收方接口

如下:

当服务调用发调用服务时候,调用方传参数过来,但是接受方接口里的参数对象里的属性全部为空。

解决方案

如下:

第一次尝试:

所有的属性上面都加上@JsonProperty(value=属性名),无效

第二次尝试 :

所有的属性上面都加上@JsonProperty(value=属性名第一个字母大写),无效

第三次尝试:

没有传值的属性上面不要加@JsonProperty注解 有效

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

原文链接:https://blog.csdn.net/qq_42422368/article/details/109381309

查看更多关于FeignClient实现接口调用方式(不同参数形式)的详细内容...

  阅读:47次