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

      

  • 相关阅读:
    这个 bug 让我更加理解 Spring 单例了
    SpringBoot
    codeblocks笔记
    https://docs.platformio.org/en/latest/boards/index.html
    外部存储的烧写
    嵌入式AI
    python的一些库
    语音芯片及解决方案
    神奇的调试值“DEADBEEF”
    【12月】+我与rt_thread的“江湖恩怨”
  • 原文地址:https://www.cnblogs.com/tianchao/p/12462512.html
Copyright © 2011-2022 走看看