java Method has too many Body parameters SpringCloud Feign
SpringCloud Feign报错:Method has too many Body parameters报错Caused by: java.lang.IllegalStateException: Method has too many Body parameters:RequestParam注解当rpc调用有多个参数时,以下写法错误@RequestMapping(value="/get",
·
SpringCloud Feign报错:Method has too many Body parameters
报错
Caused by: java.lang.IllegalStateException: Method has too many Body parameters:
RequestParam注解
当rpc调用有多个参数时,以下写法错误
@RequestMapping(value="/get")
String get( String name, int sex);
正确写法参数应该加上@RequestParam(“xxx”),指定请求类型get、post或其他。
@GetMapping(value="/get")
String get(@RequestParam("name") String name, @RequestParam("sex") int sex);
RequestBody注解
RequestBody注解错误写法
@PostMapping(value="/save")
int save(@RequestBody Student student, @RequestBody Teacher teacher);
正确写法
@PostMapping(value="/save")
int save(@RequestBody Student student,(@RequestParam("name") String name, @RequestParam("sex") int sex);
feign中你可以有多个@RequestParam,但只能有不超过一个@RequestBody,@RequestBody用来修饰对象,但是既有@RequestBody也有@RequestParam,那么参数就要放在请求的url中,@RequestBody修饰的就要放在提交对象中。
注意 用来处理@RequestBody Content-Type 为 application/json、application/xml编码的内容
更多推荐
已为社区贡献1条内容
所有评论(0)