Spring Cloud Feign接口返回流的實現(xiàn)
更新時間:2019年10月13日 10:13:01 作者:java干貨
這篇文章主要介紹了Spring Cloud Feign接口返回流的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
服務(wù)提供者
@GetMapping("/{id}")
public void queryJobInfoLogDetail(@PathVariable("id") Long id, HttpServletResponse response) {
File file = new File("xxxxx");
InputStream fileInputStream = new FileInputStream(file);
OutputStream outStream;
try {
outStream = response.getOutputStream();
byte[] bytes = new byte[1024];
int len = 0;
while ((len = fileInputStream.read(bytes)) != -1) {
outStream.write(bytes, 0, len);
}
fileInputStream.close();
outStream.close();
outStream.flush();
} catch (IOException e) {
log.error("exception", e);
}
}
client 客戶端
@GetMapping(value = "/{id}", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
feign.Response queryJobInfoLogDetail(@PathVariable("id") Long id);
服務(wù)消費者
@GetMapping("/{id}")
public void queryJobInfoLogInfoList(@PathVariable("id") Long id, HttpServletResponse servletResponse) {
Response response = apiServices.queryJobInfoLogDetail(id);
Response.Body body = response.body();
InputStream fileInputStream = null;
OutputStream outStream;
try {
fileInputStream = body.asInputStream();
outStream = servletResponse.getOutputStream();
byte[] bytes = new byte[1024];
int len = 0;
while ((len = fileInputStream.read(bytes)) != -1) {
outStream.write(bytes, 0, len);
}
fileInputStream.close();
outStream.close();
outStream.flush();
} catch (Exception e) {
}
}
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot @ConfigurationProperties注解的簡單使用
即便現(xiàn)在簡化了配置,但是一個獨立的配置文件總是易于理解而且使人安心的。Spring在構(gòu)建完項目后,會默認在resources文件夾下創(chuàng)建一個application.properties文件,application.yml也是一樣的效果。@ConfigurationProperties可以獲取配置文件中的數(shù)據(jù),將其注入類。2021-05-05
詳解MyBatis Mapper 代理實現(xiàn)數(shù)據(jù)庫調(diào)用原理
這篇文章主要介紹了詳解MyBatis Mapper 代理實現(xiàn)數(shù)據(jù)庫調(diào)用原理,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-10-10
Java Collections集合繼承結(jié)構(gòu)圖_動力節(jié)點Java學院整理
這篇文章主要介紹了Java Collections集合繼承結(jié)構(gòu)圖_動力節(jié)點Java學院整理,需要的朋友可以參考下2017-04-04
Spring?Boot?中的?Native?SQL基本概念及使用方法
在本文中,我們介紹了 Spring Boot 中的 Native SQL,以及如何使用 JdbcTemplate 和 NamedParameterJdbcTemplate 來執(zhí)行自定義的 SQL 查詢或更新語句,需要的朋友跟隨小編一起看看吧2023-07-07
POI XSSFSheet shiftRows bug問題解決
這篇文章主要介紹了POI XSSFSheet shiftRows bug問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07
java 實現(xiàn)微信服務(wù)器下載圖片到自己服務(wù)器
這篇文章主要介紹了 java 實現(xiàn)微信服務(wù)器下載圖片到自己服務(wù)器的相關(guān)資料,需要的朋友可以參考下2017-05-05
Java 向上轉(zhuǎn)型和向下轉(zhuǎn)型的詳解
這篇文章主要介紹了 Java 向上轉(zhuǎn)型和向下轉(zhuǎn)型的詳解的相關(guān)資料,需要的朋友可以參考下2017-04-04

