天天看點

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;
    }
           

繼續閱讀