SpringCloud Feign报错 Caused by: java.lang.IllegalStateException: Method has too many Body parameters

SpringCloud Feign报错 Caused by: java.lang.IllegalStateException: Method has too many Body parameters

绿林寻猫
2021-12-08 / 0 评论 / 353 阅读 / 正在检测是否收录...

Caused by: java.lang.IllegalStateException: Method has too many Body parameters:
 public abstract com.hujiang.framework.web.domain.AjaxResult com.hujiang.project.zhgd.client.SystemClient.getSystemPrivileges_app(java.lang.Integer,java.lang.Integer)

GET方式

错误写法

@RequestMapping(value="/test", method=RequestMethod.GET)  
User test(String name,  int age);  

启动服务的时候,会报如下异常:

Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.hujiang.framework.web.domain.AjaxResult com.hujiang.project.zhgd.client.SystemClient.getSystemPrivileges_app(java.lang.Integer,java.lang.Integer)

异常原因:当使用Feign时,如果发送的是get请求,那么需要在请求参数前加上@RequestParam注解修饰,Controller里面可以不加该注解修饰。

正确写法

@RequestMapping(value="/test", method=RequestMethod.GET)  
User test(@RequestParam("name")  String name,@RequestParam("age")   int age);  

POST方式

 

错误写法

public int save(@RequestBody Person p, @RequestBody  UserModel user);

feign中你可以有多个@RequestParam,但只能有不超过一个@RequestBody。

正确写法

public int save(@RequestBody Person p,@RequestParam("userId") String userId,@RequestParam("userTel") String userTel);

 

0

评论 (0)

取消