SpringCloud FeignClient 报错:Method has too many Body parameters

编程入门 行业动态 更新时间:2024-10-12 01:24:38

SpringCloud FeignClient <a href=https://www.elefans.com/category/jswz/34/1771188.html style=报错:Method has too many Body parameters"/>

SpringCloud FeignClient 报错:Method has too many Body parameters


1 Feign多参数问题

1.1 GET 方式

错误写法

@GetMapping(value="/test")  
Model test(final String name,  final int age);  

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

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里面可以不加该注解修饰


正确写法

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

1.2 POST 方式

错误写法

@PostMapping(value="/test")  
public int save(@RequestBody final Person p, @RequestBody final UserModel user);

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


正确写法

@PostMapping(value="/test") 
public int save(@RequestBody final Person p,@RequestParam("userId") String userId,@RequestParam("userTel") String userTel);

2 参考文章

SpringCloud Feign报错:Method has too many Body parameters


微信搜索【源码兴趣圈】,关注龙台,回复【资料】领取涵盖 GO、Netty、SpringCLoud Alibaba、Seata、开发规范、面试宝典、数据结构等电子书 or 视频学习资料!

更多推荐

SpringCloud FeignClient 报错:Method has too many Body parameters

本文发布于:2024-03-10 07:12:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1727323.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   FeignClient   SpringCloud   parameters   Body

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!