OpenFeign @PathVariable需注明参数名称

在定义 OpenFeign 的远程接口时,如果是路径拼接作为参数的远程接口,需要在@PathVariable需注明参数名称,不然代码启动时会报错。

  • 正例
    @FeignClient(value = ServiceConstants.SYSTEM, fallbackFactory = RemoteFileFallbackFactory.class)
    public interface RemoteFileService {
    
        /**
         * 使文件生效
         * @param id 文件ID
         * @return 结果
         */
        @PutMapping("file/enable/{id}")
        BaseResult<Boolean> enable(@PathVariable("id") Long id);
    }
    
  • 反例
    @FeignClient(value = ServiceConstants.SYSTEM, fallbackFactory = RemoteFileFallbackFactory.class)
    public interface RemoteFileService {
    
        /**
         * 使文件生效
         * @param id 文件ID
         * @return 结果
         */
        @PutMapping("file/enable/{id}")
        BaseResult<Boolean> enable(@PathVariable Long id);
    }
    
posted @ 2024-05-08 18:05  天航星  阅读(60)  评论(0编辑  收藏  举报