feign传递map
时间: 2023-08-08 22:04:45 浏览: 135
使用Feign实现微服务间文件传输
在使用Feign进行请求时,如果需要传递Map参数,可以通过以下方式解决。首先,在Feign的配置类中注入SpringFormEncoder来支持Map传参时的表单参数编码。具体代码如下:
```java
@Configuration
public class FeignConfig {
@Bean
public Encoder feignFormEncoder(ObjectFactory<HttpMessageConverters> converters) {
return new SpringFormEncoder(new SpringEncoder(converters));
}
}
```
然后,在Feign接口的方法上添加`consumes="application/x-www-form-urlencoded"`注解,并将参数声明为`@RequestBody Map<String, ?>`。示例代码如下:
```java
@PostMapping(value = "/feign/sayHelloWithMap", consumes = "application/x-www-form-urlencoded")
String sayHelloWithMap(@RequestBody Map<String, ?> map);
```
这样就可以通过Feign传递Map参数了。\[1\]
#### 引用[.reference_title]
- *1* [springcloud openfeign通过map传递form表单参数](https://blog.csdn.net/LeoHan163/article/details/127269671)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [.form文件_Feign完美解决服务之间传递文件、传递list,map、对象等情况](https://blog.csdn.net/weixin_39982537/article/details/110252979)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [springcloud feign 传递map 对象 多媒体文件](https://blog.csdn.net/sswltt/article/details/80415284)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文