当前位置: 首页 > news >正文

廊坊企业网站服务珠海左右创意园网站开发

廊坊企业网站服务,珠海左右创意园网站开发,小程序公司排名前十,国内三大oa系统在Spring Cloud封装的Feign中并不直接支持传文件#xff0c;但可以通过引入Feign的扩展包来实现#xff0c;本来就来具体说说如何实现。 服务提供方#xff08;接收文件#xff09; 服务提供方的实现比较简单#xff0c;就按Spring MVC的正常实现方式即可#xff0c;比…在Spring Cloud封装的Feign中并不直接支持传文件但可以通过引入Feign的扩展包来实现本来就来具体说说如何实现。 服务提供方接收文件 服务提供方的实现比较简单就按Spring MVC的正常实现方式即可比如 EnableFeignClientsEnableDiscoveryClientSpringBootApplicationpublic class Application { RestController public class UploadController { PostMapping(value /uploadFile, consumes MediaType.MULTIPART_FORM_DATA_VALUE) public String handleFileUpload(RequestPart(value file) MultipartFile file) { return file.getName(); } } public static void main(String[] args) { new SpringApplicationBuilder(Application.class).web(true).run(args); }}服务消费方发送文件 在服务消费方由于会使用Feign客户端所以在这里需要在引入feign对表单提交的依赖具体如下 dependency groupIdio.github.openfeign.form/groupId artifactIdfeign-form/artifactId version3.0.3/version/dependencydependency groupIdio.github.openfeign.form/groupId artifactIdfeign-form-spring/artifactId version3.0.3/version/dependencydependency groupIdcommons-fileupload/groupId artifactIdcommons-fileupload/artifactId version1.3.3/version/dependency定义文件上传方的应用主类和FeignClient假设服务提供方的服务名为eureka-feign-upload-server EnableFeignClientsEnableDiscoveryClientSpringBootApplicationpublic class Application { public static void main(String[] args) { new SpringApplicationBuilder(Application.class).web(true).run(args); }}FeignClient(value upload-server, configuration UploadService.MultipartSupportConfig.class)public interface UploadService { PostMapping(value /uploadFile, consumes MediaType.MULTIPART_FORM_DATA_VALUE) String handleFileUpload(RequestPart(value file) MultipartFile file); Configuration class MultipartSupportConfig { Bean public Encoder feignFormEncoder() { return new SpringFormEncoder(); } } }在启动了服务提供方之后尝试在服务消费方编写测试用例来通过上面定义的Feign客户端来传文件比如 Slf4jRunWith(SpringJUnit4ClassRunner.class)SpringBootTestpublic class UploadTester { Autowired private UploadService uploadService; Test SneakyThrows public void testHandleFileUpload() { File file new File(upload.txt); DiskFileItem fileItem (DiskFileItem) new DiskFileItemFactory().createItem(file, MediaType.TEXT_PLAIN_VALUE, true, file.getName()); try (InputStream input new FileInputStream(file); OutputStream os fileItem.getOutputStream()) { IOUtils.copy(input, os); } catch (Exception e) { throw new IllegalArgumentException(Invalid file: e, e); } MultipartFile multi new CommonsMultipartFile(fileItem); log.info(uploadService.handleFileUpload(multi)); }}完整示例 读者可以根据喜好选择下面的两个仓库中查看eureka-feign-upload-server和eureka-feign-upload-client两个项目 Githubhttps://github.com/dyc87112/SpringCloud-Learning/Giteehttps://gitee.com/didispace/SpringCloud-Learning/ 如果您对这些感兴趣欢迎star、follow、收藏、转发给予支持
http://www.zqtcl.cn/news/863924/

相关文章:

  • 江门网页建站模板金富通青岛建设工程有限公司网站
  • 网站后台账户如何做会计分录做传奇开服一条龙网站哪个好
  • 天门市网站建设seo平台建设网站公司
  • php网站怎么做302织梦网站有会员系统怎么做
  • 清远建设局网站安阳吧百度贴吧
  • 做什么软件做网站效率最好网站公司建设都招聘那些职位
  • 缙云建设局网站深圳营销型网站设计
  • 企业网站制作价格成都高端网站建设公司哪家好
  • wordpress+做仿站网站建设费用属于业务宣传费吗
  • 昆明企业网站制作wordpress移动端插件menu
  • 长沙网站设计培训学校南宁建设网站哪里好
  • 提高基层治理效能全国seo搜索排名优化公司
  • 如何建设网站简介WordPress集成tipask
  • 青海网站开发公司建筑公司的愿景怎么写
  • 建设银行集团网站首页优化科技
  • dede 汽车网站网站上的彩票走势图是怎么做的
  • 网站内容营销呼市推广网站
  • 南宁网站建设价格医院有关页面设计模板
  • 城乡住房和城乡建设厅网站湖州公司网站建设
  • h5响应式的网站建站空间哪个好
  • 徐州网站建设与推广公众号开发技术风险
  • 男女做差差事的视频网站自己做一个小程序要多少钱
  • 临沂网站建设哪家好重庆建设招标造价信息网站
  • 筑巢网络官方网站深圳网站开发设计公司排名
  • 镇江市网站制作网页的代码实例
  • 吉林省网站制作公司有哪些唐山设计网站公司
  • 浙江国泰建设集团有限公司网站ps软件下载电脑版免费怎么下载
  • 昆明网站建设价格自力教育
  • 黄冈网站推广软件视频下载孝感做网站xgsh
  • 用jsp做一网站的流程图互联网博客网站