feign客戶端傳參數報錯 Caused by: java.lang.IllegalStateException: Method has too many Body parameters

新手常常遇到的錯誤html

Caused by: java.lang.IllegalStateException: Method has too many Body parameters

feign多參數問題
1.1GET方式
錯誤寫法java

@RequestMapping(value="/test", method=RequestMethod.GET)spring

Model test(final String name, final int age);springboot

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

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)app

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

正確寫法url

@RequestMapping(value="/test", method=RequestMethod.GET)rest

Model test(@RequestParam("name") final String name,@RequestParam("age") final int age);htm

1.1POST方式
錯誤寫法

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

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

正確寫法

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

相關文章
相關標籤/搜索