最近在用springcloud的Feign写项目时,定义feign 声明式客户端接口时报了这两个问题:
便是这段代码里:
@GetMapping(value = "/{userId}/score")
JsonResult<?> addScore(@PathVariable Integer userId,
@RequestParam Integer score);//@RequestParam在Controller中可以省略,此处不能省略
在声明式客户端接口里,使用@PathVariable和@RequestParam这两个注解时需要指定value参数,(注:有的springboot版本里就不需要指定,他们可以直接编译通过,就莫名其妙)
那么正确的代码便是如下:
@GetMapping(value = "/{userId}/score")
JsonResult<?> addScore(@PathVariable(value = "userId") Integer userId,
@RequestParam(value = "score") Integer score);//@RequestParam在Controller中可以省略,此处不能省略
将@PathVariable和@RequestParam这两个注解的value指出,便不再报错。