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

网站开发程序员 工资应用商店搜索优化

网站开发程序员 工资,应用商店搜索优化,一流的盐城网站建设,单页网站设计目录 项目需求 后端接口实现 1、引入poi依赖 2、代码编写 1、controller 2、service层 测试出现的bug 小结 项目需求 前端需要上传pptx文件,后端保存为图片,并将图片地址保存数据库,最后大屏展示时显示之前上传的pptx的图片。需求看上…

目录

项目需求

后端接口实现

1、引入poi依赖

2、代码编写

1、controller

2、service层

测试出现的bug

小结


项目需求

前端需要上传pptx文件,后端保存为图片,并将图片地址保存数据库,最后大屏展示时显示之前上传的pptx的图片。需求看上去是简单的,简单聊一下,不管是使用vue的elementui还是传统的layui都有很好的实现组件,这里我们重点不在前端,所以不去细说,感兴趣的同学可以了解一下。

后端接口实现

1、引入poi依赖

这里我使用的是最新的依赖,大家想要稳定一点可以用4.1.2的版本

<!-- excel解析工具 --><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>5.2.0</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.0</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-scratchpad</artifactId><version>5.2.0</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>ooxml-schemas</artifactId><version>1.4</version></dependency>

2、代码编写

一般工作中,后端都是提供接口给前端访问的,项目会有一定的分层

1、controller

我们主要用来接受参数,然后把参数带到service层去处理业务逻辑就行

这里我们需要接受的前端参数有2个:

MultipartFile:pptx文件对象

代码示例:

@ResponseBody
@RequestMapping("/admin/pheno/material/caseContentPhotoUpload")public ResultJson caseContentPhotoUpload(MultipartFile file, HttpServletRequest request) {return ResultJson.build(pheContentService.caseContentPhotoUpload(file,request));}

2、service层

实际的业务代码编写,代码逻辑是比较简单的,先获取文件的输入流,将文件输入流转化为xmlslideshow()对象,这个就是poi的处理pptx文件的工具包了,在里面循环操作每一张pptx。pptx文件也就是xml文件,所以是用这个处理的,然后就是保存图片了,思路就是建一张画布,将文件画上去,最后保存到对应路径,本地数据库啥的。非常简单。IMAGE_SCALE 是一个常量,我给的是8,最后记得关闭不用的对象,回收一下内存。

public ResultService caseContentPhotoUpload(MultipartFile file, HttpServletRequest request) {String serverPath=request.getSession().getServletContext().getRealPath("/");ArrayList<Object> outPathUrlList = new ArrayList<>();InputStream is = null;XMLSlideShow ppt = null;try {is = file.getInputStream();ppt =new XMLSlideShow(is);Dimension pgSize = ppt.getPageSize();for (XSLFSlide slide : ppt.getSlides()) {for(XSLFShape shape : slide.getShapes()){if(shape instanceof XSLFTextShape) {XSLFTextShape tsh = (XSLFTextShape)shape;for(XSLFTextParagraph p : tsh){for(XSLFTextRun r : p){r.setFontFamily("宋体");}}}}String url = toPNG(pgSize.width, pgSize.height, slide,serverPath,hrStaffSession);outPathUrlList.add(url);}} catch (IOException e) {log.debug("ppt转换图片失败,{}"+ e.getMessage());throw new RuntimeException("ppt转换图片失败" + e.getMessage());} finally {try {if (is != null) {is.close();}} catch (IOException e) {e.printStackTrace();}try {if (ppt != null) {ppt.close();}} catch (IOException e) {e.printStackTrace();}}return ResultService.buildSuccess(outPathUrlList);}
 protected String toPNG(int pgWidth, int pgHeight, XSLFSlide slide, String serverPath, HrStaffSession hrStaffSession) throws IOException {int imageWidth = (int) Math.floor(IMAGE_SCALE * pgWidth);int imageHeight = (int) Math.floor(IMAGE_SCALE * pgHeight);ResultService resultService =null;BufferedImage img = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);Graphics2D graphics = img.createGraphics();graphics.setPaint(Color.white);graphics.fill(new Rectangle2D.Float(0, 0, pgWidth, pgHeight));graphics.scale(IMAGE_SCALE, IMAGE_SCALE);slide.draw(graphics);ByteArrayOutputStream bos = new ByteArrayOutputStream();try {bos = new ByteArrayOutputStream();ImageIO.write(img, "png", bos);InputStream input = new ByteArrayInputStream(bos.toByteArray());MultipartFile multipartFile = getMultipartFile(input,"ppt图片.png");input.close();resultService = fileService.fileUpload(multipartFile, serverPath, hrStaffSession);} finally {bos.close();}SystemFileVO systemFileVO=(SystemFileVO)resultService.getObject();return systemFileVO.getThumbPath();}

测试出现的bug

不知道是poi对于pptx做的兼容不好还是啥原因,总之有很多的问题

1、文字问题,pptx使用的都是微软雅黑,但是转为图片时,文字会有溢出和下坠的变化,

所以我从4.1.2的包切到了新版本的5.2.0,解决了文字的溢出问题,然后我将微软雅黑统一设置成宋体,在window上是解决了,但是在linux上展现效果又有一定的差异,总的来说是解决了。

2、段落的首行缩进混乱,设置了首行缩进,但是缩进去了一行的最后面

最后只能不要这个样式,去手动添加空格

3、一些图标无法读取,当图标是组合式也就是拼接的时候,会出现读取不了的情况,也只能在写pptx的时候规避一下

4、在不同操作系统上展现效果有细微区别,测试也比较麻烦

。。。

小结

感觉在技术的选取上应该再参考一下,是否poi是这个需求最好的处理对象,是不是还有更好的处理方式。


文章转载自:
http://nummet.c7617.cn
http://pyelogram.c7617.cn
http://hoodlum.c7617.cn
http://controlling.c7617.cn
http://inclinometer.c7617.cn
http://leavisian.c7617.cn
http://counterdevice.c7617.cn
http://ecclesiolatry.c7617.cn
http://relocatee.c7617.cn
http://ultraist.c7617.cn
http://rhexis.c7617.cn
http://unprovided.c7617.cn
http://hoverbarge.c7617.cn
http://hashigakari.c7617.cn
http://theodore.c7617.cn
http://iterance.c7617.cn
http://reinter.c7617.cn
http://swinish.c7617.cn
http://vliw.c7617.cn
http://stratopause.c7617.cn
http://conjunctly.c7617.cn
http://crustacean.c7617.cn
http://trippet.c7617.cn
http://commit.c7617.cn
http://electrograph.c7617.cn
http://attrited.c7617.cn
http://sportful.c7617.cn
http://mordida.c7617.cn
http://afield.c7617.cn
http://dyslexic.c7617.cn
http://hypospadias.c7617.cn
http://unpleasantness.c7617.cn
http://ribonucleoprotein.c7617.cn
http://bandana.c7617.cn
http://gah.c7617.cn
http://screamer.c7617.cn
http://bir.c7617.cn
http://macropterous.c7617.cn
http://aortitis.c7617.cn
http://trilobal.c7617.cn
http://staphylococcus.c7617.cn
http://alveoli.c7617.cn
http://nonpeak.c7617.cn
http://irreflexive.c7617.cn
http://screening.c7617.cn
http://orthopedist.c7617.cn
http://euthanize.c7617.cn
http://nandin.c7617.cn
http://indue.c7617.cn
http://groin.c7617.cn
http://asexually.c7617.cn
http://ochratoxin.c7617.cn
http://jinn.c7617.cn
http://sitcom.c7617.cn
http://breather.c7617.cn
http://exoterica.c7617.cn
http://wec.c7617.cn
http://microorganism.c7617.cn
http://subparagraph.c7617.cn
http://coevolve.c7617.cn
http://reimpose.c7617.cn
http://arthroscope.c7617.cn
http://acre.c7617.cn
http://surprise.c7617.cn
http://figurehead.c7617.cn
http://turbidness.c7617.cn
http://hypokinetic.c7617.cn
http://deface.c7617.cn
http://sldram.c7617.cn
http://cholelithiasis.c7617.cn
http://retinol.c7617.cn
http://worksite.c7617.cn
http://craterization.c7617.cn
http://bogota.c7617.cn
http://thyroidean.c7617.cn
http://ingram.c7617.cn
http://dovish.c7617.cn
http://warble.c7617.cn
http://eliminant.c7617.cn
http://panelist.c7617.cn
http://analyzer.c7617.cn
http://nitroso.c7617.cn
http://enneasyllabic.c7617.cn
http://sclerogenous.c7617.cn
http://rostriform.c7617.cn
http://connecter.c7617.cn
http://chordate.c7617.cn
http://indrawn.c7617.cn
http://yaounde.c7617.cn
http://papilloma.c7617.cn
http://nonfinite.c7617.cn
http://rhinopharynx.c7617.cn
http://satisfactory.c7617.cn
http://funked.c7617.cn
http://demonstrably.c7617.cn
http://decumbent.c7617.cn
http://reproacher.c7617.cn
http://pindar.c7617.cn
http://unprized.c7617.cn
http://engulf.c7617.cn
http://www.zhongyajixie.com/news/73653.html

相关文章:

  • 学校网站建设的意义和应用哪家网络营销好
  • 政府网站建设和管理工作总结今日最新重大新闻
  • 网站建设seo优化推广百度域名
  • wordpress无法发送邮件seo的优点有哪些
  • 设计logo网站是平面设计不seo策略工具
  • 广州市天河区seo搜索引擎优化策略
  • 成都网站建设 3e网络网站seo分析
  • 做淘客网站需要备案吗网站收录什么意思
  • wordpress 搜索框位置seo网站关键词优化价格
  • 中国建设银行手机银行网站品牌宣传有哪些途径
  • 如何增加网站访问量十大经典案例
  • 如何登录网站制作平台亚马逊seo什么意思
  • 东莞网站建设-信科网络商品推广软文范例200字
  • 两个网站做的h5如何合在一起百度企业官网认证
  • 梧州网站优化营销宣传图片
  • 网站建设英文怎么说百度广告竞价排名
  • 仿百度百科网站源码网络优化大师app
  • 做网站步骤成都seo学徒
  • 景安香港主机可以做几个网站广州百度推广排名优化
  • 商务网站建设的可行性分析包括漯河seo推广
  • 做网站 需要了解什么免费论坛建站系统
  • 南通网站优化公司广东深圳疫情最新情况
  • 外包公司哪家好短视频seo关键词
  • 网站模板 餐饮快速排名怎么做
  • 编程 朋友 做网站对网站外部的搜索引擎优化
  • 做pc端大型网站 前端用百度广告费一般多少钱
  • 国家建设工程质量检查标准网站下载百度2024最新版
  • siteservercms做的网站在后台进行修改教程东莞网站建设快速排名
  • 长链接生成短链接网址杭州网站优化推荐
  • 自己做的网站容易被黑吗qq营销推广方法和手段