天天看点

Spring Cloud中使用feign传参的方式

1.使用feign传递单个参数

接口:

/*feign传递参数--单个参数*/
    @RequestMapping("/getById")
    public Products getById(@RequestParam("id") Integer id);
           

实现类:

@Override
    public Products getById(@RequestParam("id") Integer id) {
        return new Products(id,"MyProduct"+id);
    }
           

2.使用feign传递多个参数–Get方式

接口:

/*feign传递参数--多个参数--Get方式*/
    @RequestMapping(value = "getOne1"/*,method = RequestMethod.GET*/)
    public Products getGet(@RequestParam("id") Integer id,@RequestParam("name") String name);
           

实现类:

@Override
    public Products getGet(@RequestParam("id") Integer id,@RequestParam("name") String name) {
        return new Products(id,name);
    }
           

3.使用feign传递多个参数–Post方式

接口:

/*feign传递参数--多个参数--Post方式*/
    @RequestMapping(value = "getOne2",method = RequestMethod.POST)
    public Products getPost(@RequestBody Products products);
           

实现类:

@Override
    public Products getPost(@RequestBody Products products) {
        return products;
    }
           

继续阅读