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)文章
Spring如何基于Proxy及cglib實現(xiàn)動態(tài)代理
這篇文章主要介紹了Spring如何基于Proxy及cglib實現(xiàn)動態(tài)代理,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-06-06Java httpcomponents發(fā)送get post請求代碼實例
這篇文章主要介紹了Java httpcomponents發(fā)送get post請求代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-09-09SpringBoot的@Value注解如何設(shè)置默認值
這篇文章主要介紹了SpringBoot的@Value注解如何設(shè)置默認值問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02MyBatis-Plus動態(tài)表名使用selectPage方法不生效問題解析與解決方案
MyBatis-Plus是MyBatis的增強工具,動態(tài)表名是MyBatis-Plus的一個重要功能之一,一些開發(fā)者在使用selectPage方法時可能會遇到動態(tài)表名不生效的問題,本文將深入分析這個問題的原因,并提供相應(yīng)的解決方案,需要的朋友可以參考下2023-12-12