Feign传递参数

发布时间 2023-04-20 14:35:52作者: 鲤斌

传递单个参数

1客户端
    @RequestMapping("/one")
    public BaseResp one(@RequestParam("id") Integer id);
服务端
    @RequestMapping("/one")
    public BaseResp one(@RequestParam("id") Integer id){
        return  new BaseResp(200,"这是一@RequestParam(\"id\") Integer id个传单值的测试",id,null);
    }
2客户端
    @RequestMapping("/one1")
    public BaseResp one1( Integer id);
服务端
    @RequestMapping("/one1")
    public BaseResp one1( Integer id){
        return  new BaseResp(200,"这是一个Integer id传单值的测试",id,null);
    }
3客户端
    @RequestMapping("/one2/{id}")
    public BaseResp one2(@PathVariable("id") Integer id);
服务端
    @RequestMapping("/one2/{id}")
    public BaseResp one2(@PathVariable("id") Integer id){
        return  new BaseResp(200,"@PathVariable(\"id\") Integer id",id,null);
    }

传递多个参数

4客户端
    @RequestMapping("/two1")
    public BaseResp two1(  @RequestParam("id") Integer id,@RequestParam("name") String name);
服务端
    @RequestMapping("/two1")
    public BaseResp two1( Integer id, String name){
        return  new BaseResp(200,"Integer id, String name这是一个多值传参的测试",id+":"+name,null);
    }

传递对象

5客户端
    @RequestMapping("/books")
    public BaseResp books(@SpringQueryMap Books book);
服务端
    @RequestMapping("/books")
    public BaseResp books( Books book){
        return  new BaseResp(200," Book book是一个多值传参的测试",book,null);
    }
6客户端
@RequestMapping(value = "/book2", method = RequestMethod.POST)
    public BaseResp book2(@RequestBody Books book);
服务端
    @RequestMapping("/book2")
    public BaseResp book2(@RequestBody Books book){
        return  new BaseResp(200,"@RequestBody Book book一个多值传参的测试",book,null);
    }

传递多个参数与对象

7客户端
    @RequestMapping("/bookAndOne")
    public BaseResp bookAndOne(@SpringQueryMap  Books book,@RequestParam("id") Integer id,@RequestParam("name") String name);
}
服务端
    @RequestMapping("/bookAndOne")
    public BaseResp bookAndOne( Books book, Integer id, String name){
        return  new BaseResp(200,"多值和对象传参的测试",book+":"+id+":"+name,null);
    }