網(wǎng)站首頁 編程語言 正文
創(chuàng)建配置類
package com.thecarevoice.frontend.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
/**
* @ClassName FeignMultipartSupportConfig
* @Description TODO
* @Author yanqing.liu
* @Date 2022/5/12 2:06 下午
* @Version 1.0
*/
@Configuration
public class FeignMultipartSupportConfig {
@Bean
@Primary
@Scope("prototype")
public Encoder multipartFormEncoder() {
return new SpringFormEncoder();
}
@Bean
public feign.Logger.Level multipartLoggerLevel() {
return feign.Logger.Level.FULL;
}
}
api
@PostMapping("upload")
@ApiOperation("圖片上傳")
public ResultResponse<JSONObject> upload( @RequestParam("file") MultipartFile multipartFile){
return null
}
FeignClient
package com.thecarevoice.frontend.adaptor;
import com.alibaba.fastjson.JSONObject;
import com.thecarevoice.frontend.config.FeignMultipartSupportConfig;
import com.thecarevoice.frontend.response.ResultResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
/**
* @ClassName FoodController
* @Description TODO
* @Author yanqing.liu
* @Date 2022/5/10 5:49 下午
* @Version 1.0
*/
@FeignClient(value = "fileAdaptor",url="${health.data.adaptor.host}",configuration = FeignMultipartSupportConfig.class)
public interface FileAdaptor {
/**
* 上傳食品圖片
* @param multipartFile
* @return
*/
@RequestMapping(value = "/api/v1/food/upload",
produces = {MediaType.APPLICATION_JSON_VALUE},
consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
ResultResponse<JSONObject> upload(@RequestPart("file") MultipartFile multipartFile);
}
原文鏈接:https://blog.csdn.net/ityqing/article/details/124730327
相關(guān)推薦
- 2022-10-16 python?math模塊使用方法介紹_python
- 2022-08-14 Hyper-V設(shè)置虛擬機(jī)固定Ip的方法步驟_Hyper-V
- 2023-01-01 Kotlin?ContentProvider使用方法詳解_Android
- 2022-11-21 深入了解Golang官方container/heap用法_Golang
- 2022-12-16 python字典添加值的方法及實(shí)例代碼分享_python
- 2022-12-24 Docker網(wǎng)絡(luò)模型以及容器通信詳解續(xù)篇_docker
- 2023-01-09 C#使用stackalloc分配堆棧內(nèi)存和非托管類型詳解_C#教程
- 2022-05-19 Python中的logging模塊實(shí)現(xiàn)日志打印_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支