feign支持post表单

1、定义Feign的form编码器,让Feign支持form表单提交

package com.test.config;

import feign.Logger;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@RequiredArgsConstructor
@EnableFeignClients(basePackages = {"com.test.feign"})
@Configuration
public class OpenFeignConfig {

    private final ObjectFactory<HttpMessageConverters> messageConverters;

    @Bean
    public Encoder feignFormEncoder() {
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }
}

2、定义feignclient

package com.test.feign.test;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;
import java.util.Map;

@FeignClient(value = "test", url = "http://test.com")
public interface TestClient {

    @PostMapping(value = "/test", consumes = "application/x-www-form-urlencoded;charset=UTF-8")
    Result<List<TestUser>> test(Map<String,?> map);

    @PostMapping(value = "/test", consumes = "application/x-www-form-urlencoded;charset=UTF-8")
    Result<List<TestUser>> test1(TestReq req);
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容