博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用Feign实现Form表单提交
阅读量:7048 次
发布时间:2019-06-28

本文共 1921 字,大约阅读时间需要 6 分钟。

  hot3.png

原文:

之前,笔者写了《》。近日,有同事在对接遗留的Struts古董系统,需要使用Feign实现Form表单提交。其实步骤大同小异,本文附上步骤,算是对之前那篇的补充。

<!-- more -->

  • 添加依赖:

    io.github.openfeign.form
    feign-form
    3.2.2
    io.github.openfeign.form
    feign-form-spring
    3.2.2
  • Feign Client示例:

    @FeignClient(name = "xxx", url = "http://www.itmuch.com/", configuration = TestFeignClient.FormSupportConfig.class)public interface TestFeignClient {    @PostMapping(value = "/test",            consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE},            produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}            )    void post(Map
    queryParam); class FormSupportConfig { @Autowired private ObjectFactory
    messageConverters; // new一个form编码器,实现支持form表单提交 @Bean public Encoder feignFormEncoder() { return new SpringFormEncoder(new SpringEncoder(messageConverters)); } // 开启Feign的日志 @Bean public Logger.Level logger() { return Logger.Level.FULL; } }}
  • 调用示例:

    @GetMapping("/user/{id}")public User findById(@PathVariable Long id) {  HashMap
    param = Maps.newHashMap(); param.put("username","zhangsan"); param.put("password","pwd"); this.testFeignClient.post(param); return new User();}
  • 日志:

    ...[TestFeignClient#post] ---> POST http://www.baidu.com/test HTTP/1.1...[TestFeignClient#post] Accept: application/json;charset=UTF-8...[TestFeignClient#post] Content-Type: application/x-www-form-urlencoded; charset=UTF-8...[TestFeignClient#post] Content-Length: 30...[TestFeignClient#post] ...[TestFeignClient#post] password=pwd&username=zhangsan...[TestFeignClient#post] ---> END HTTP (30-byte body)

    由日志可知,此时Feign已能使用Form表单方式提交数据。

参考文档

转载于:https://my.oschina.net/eacdy/blog/1648308

你可能感兴趣的文章
ubuntu 超级管理员修改Mysql数据库密码
查看>>
社会化分享功能百度分享代码示例
查看>>
我的友情链接
查看>>
java爬虫学习日记1-基本爬虫原理介绍
查看>>
bash的功能简介
查看>>
Python中的and和or
查看>>
Linux下TFTP+NFS+PXE安装FreeBSD操作系统
查看>>
企业网络部署和运维
查看>>
win7/win8右键在目录当前打开命令cmd窗口
查看>>
定时任务1.基本原理
查看>>
linux文件操作之系统调用
查看>>
《飞机大战》安卓游戏开发源码(二)
查看>>
2017总结、计划——IT人应该拥有什么样子的价值观与实践能力
查看>>
Linux设备驱动入门之hello驱动
查看>>
vim 的一些简单使用
查看>>
maven构建spring4-hibernate4-webapp
查看>>
当网络连接再次遇上存储
查看>>
Hyper-V系列---快速导入导出虚拟机
查看>>
py文件缩进问题检查
查看>>
『ExtJS』表单(一)常用表单控件及内置验证
查看>>