feign Method has too many Body parameters

一、feign多參數問題

1.1GET方式

錯誤寫法java

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

啓動服務的時候,會報以下異常:spring

Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.chhliu.springboot.restful.vo.User com.chhliu.springboot.restful.feignclient.UserFeignClient.findByUsername(java.lang.String,java.lang.String)

異常緣由:當使用Feign時,若是發送的是get請求,那麼須要在請求參數前加上@RequestParam註解修飾,Controller裏面能夠不加該註解修飾。springboot

正確寫法restful

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

1.1POST方式

錯誤寫法app

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

feign中你能夠有多個@RequestParam,但只能有不超過一個@RequestBody。spa

正確寫法rest

public int save(@RequestBody final Person p,@RequestParam("userId") String userId,@RequestParam("userTel") String userTel);
相關文章
相關標籤/搜索