查看“OpenFeign 传递普通表单参数”的源代码
←
OpenFeign 传递普通表单参数
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
https://www.bilibili.com/video/BV1My4y1W7vy?p=4 === 被调用的 application service === <syntaxhighlight lang="java"> import io.github.jihch.pojo.People; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; import java.util.Map; @RestController public class DemoController { @RequestMapping("/demo2") public String demo2(String name, Integer age) { return "name:" + name + ",age:" + age; } } </syntaxhighlight> === 使用 OpenFeign 调用的 application client === <syntaxhighlight lang="java"> import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @FeignClient("MYPROJECT") public interface ServiceDemoFeign { /** * 在 OpenFeign 中方法参数前如果没有注解,默认添加 @RequestBody 注解,最多只能存在一个不带注解的参数 * * 普通表单参数必须添加 @RequestParam 注解。如果变量名和参数名称对应可以不写 name * * @return */ @RequestMapping("/demo2") String suiyi2(@RequestParam String name, @RequestParam Integer age); } </syntaxhighlight><syntaxhighlight lang="java"> public interface FeignDemoService { String demo(); String demo2(String name, Integer age); } </syntaxhighlight><syntaxhighlight lang="java"> import io.github.jihch.feign.ServiceDemoFeign; import io.github.jihch.service.FeignDemoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class FeignDemoServiceImpl implements FeignDemoService { @Autowired private ServiceDemoFeign serviceDemoFeign; @Override public String demo() { return serviceDemoFeign.suiyi(); } @Override public String demo2(String name, Integer age) { return serviceDemoFeign.suiyi2(name, age); } } </syntaxhighlight><syntaxhighlight lang="java"> import io.github.jihch.service.FeignDemoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class FeignDemoController { @Autowired private FeignDemoService feignDemoService; @RequestMapping("/demo") public String demo() { return feignDemoService.demo(); } @RequestMapping("/demo2") public String demo2(String name, Integer age) { return feignDemoService.demo2(name, age); } } </syntaxhighlight>访问:http://localhost:8088/demo2?name=abc&age=15 进行测试
返回至
OpenFeign 传递普通表单参数
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
Spring Boot 2 零基础入门
Spring Cloud
Spring Boot
设计模式之禅
VUE
Vuex
Maven
算法
技能树
Wireshark
IntelliJ IDEA
ElasticSearch
VirtualBox
软考
正则表达式
程序员精讲
软件设计师精讲
初级程序员 历年真题
C
SQL
Java
FFmpeg
Redis
Kafka
MySQL
Spring
Docker
JMeter
Apache
Linux
Windows
Git
ZooKeeper
设计模式
Python
MyBatis
软件
数学
PHP
IntelliJ IDEA
CS基础知识
网络
项目
未分类
MediaWiki
镜像
问题
健身
国债
英语
烹饪
常见术语
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息