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;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章