zoukankan      html  css  js  c++  java
  • springcloud中feign使用的抗

      1、feign不支持@GetMapping 和 @PostMapping 注解,只能使用 @RequestMapping 并且 method = RequestMethod.GET必须指定get或post

    // 正确写法
    @RequestMapping(value = "/user/getList", method = RequestMethod.GET)
    List<User> userList();

       2、当feign使用get方式请求时,@PathVariable注解@RequestParam必须设置value属性(@PathVariable或@RequestParam 注解在MVC中不设置value 默认使用当前变量的,但feign中必须设置)

    // 正确写法1
    @RequestMapping(value = "/user/getList", method = RequestMethod.GET)
    List<User> userList(@RequestParam(value="gradeId") Integer gradeId);
    // 正确写法2
    @RequestMapping(value = "/user/getList", method = RequestMethod.GET)
    List<User> userList(@PathVariable(value="gradeId") Integer gradeId);

      3、feign接口如果参数为复杂参数,必须使用post方式

    // 正确写法1
    @RequestMapping(value = "/user/getList", method = RequestMethod.Post)
    List<User> userList(User user);
    // 正确写法2(推荐)
    @RequestMapping(value = "/user/getList", method = RequestMethod.Post)
    List<User> userList(@RequestBody User user);

      

  • 相关阅读:
    Tire树的理解和应用
    C语言:socket简单模拟http请求
    C语言:关于socket的基础知识点
    php中的ip2long和long2ip的理解
    理解php中的pack/unpack/ord/chr
    zlog学习笔记(mdc)
    计算机工作的进行
    期末总结
    第十四周学习报告
    第十三周学习报告
  • 原文地址:https://www.cnblogs.com/tianchao/p/12462512.html
Copyright © 2011-2022 走看看