zoukankan      html  css  js  c++  java
  • feign客户端传参数报错

    新手经常遇到的错误

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

    feign多参数问题
    1.1GET方式
    错误写法

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

    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.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);

  • 相关阅读:
    一个通用的事件监听函数全集
    单应性矩阵
    opencv姿态估计
    opencv相机标定
    Harris角点
    盒滤波Box Filter
    win10+vs2015+pcl1.8.1安装配置
    图像元素遍历
    阈值分割
    二叉树的层次遍历
  • 原文地址:https://www.cnblogs.com/a1304908180/p/11043066.html
Copyright © 2011-2022 走看看