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

网站备案下来以后怎么做网页中型电商网站维护费用

网站备案下来以后怎么做网页,中型电商网站维护费用,小程序制作网站,wordpress3.5.1zhcn目录 需求一、准备模板文件二、引入Poi-tl、Apache POI依赖三、创建实体类#xff08;用于保存向Word中写入的数据#xff09;四、实现Service接口五、Controller层实现 需求 在服务端提前准备好Word模板文件#xff0c;并在用户请求接口时服务端动态获取图片。数据等信息插… 目录 需求一、准备模板文件二、引入Poi-tl、Apache POI依赖三、创建实体类用于保存向Word中写入的数据四、实现Service接口五、Controller层实现 需求 在服务端提前准备好Word模板文件并在用户请求接口时服务端动态获取图片。数据等信息插入到模板当中然后返回包含数据信息的Word文件流。 一、准备模板文件 在需要插入图片的地方使用{{参数名}}文本信息使用{{参数名}}进行占位占位格式将会被保留经过处理后格式不变 将准备好的模板文件放在resources目录下 二、引入Poi-tl、Apache POI依赖 poi-tlpoi template language是Word模板引擎基于Apache POI提供更友好的API使用起来更加简单 版本对应关系参考Poi-tl官网 !-- 替换自己使用的版本 -- dependencygroupIdorg.apache.poi/groupIdartifactIdpoi/artifactIdversion4.1.*/version /dependency dependencygroupIdorg.apache.poi/groupIdartifactIdpoi-ooxml/artifactIdversion4.1.*/version /dependency !-- Word模板引擎 -- dependencygroupIdcom.deepoove/groupIdartifactIdpoi-tl/artifactIdversion1.7.*/version /dependency 三、创建实体类用于保存向Word中写入的数据 参数名必须同Word模板中的参数名称保持一致 import com.deepoove.poi.data.PictureRenderData;Data public class DownloadDate {//图片使用PictureRenderData类型private PictureRenderData image;private String name;private String a;private String b;private String c;private String d;private String e;private String f;private String g;private String h;private String i; }四、实现Service接口 public interface DownloadService {void download(HttpServletResponse response, DownloadDTO downloadDTO) throws IOException; }Service Slf4j public class DownloadServiceImpl implements DownloadService {Resource//远程调用服务private FeignService feignService;Overridepublic void download(HttpServletResponse response, DownloadDTO downloadDTO) throws IOException {BufferedImage、字节数组Base64可以转字节数组后使用//通过调用其它接口获取待写入的数据信息WordData wordData feignService.getData(downloadDTO);/** * 图片可以是多种格式------------------------* 图片路径PictureRenderData(int width, int height, String path)* FilePictureRenderData(int width, int height, File picture)* InputStreamPictureRenderData(int width, int height, String format, InputStream input)* BufferedImagePictureRenderData(int width, int height, String format, BufferedImage image)* 字节数组PictureRenderData(int width, int height, String format, byte[] data)* Base64可以转字节数组后使用*///以Base64为例先获取图片的Base64编码wordData.getImg是原始图片Base64数据String base64ImageData wordData.getImg.substring(data.indexOf(,) 1);//获取图片类型String format getBase64Type(base64ImageData);// 将base64数据转为字节数组byte[] imageBytes Base64.getDecoder().decode(base64ImageData);// 将字节数组包装成PictureRenderDataPictureRenderData pictureRenderData new PictureRenderData(690,530,format,imageBytes);//待写入Word的数据DownloadDate downloadDate new DownloadDate();//图片信息downloadDate.setImage(pictureRenderData);//其它信息downloadDate.setName(wordData.getName());//...XWPFTemplate template null;BufferedOutputStream bufferedOutputStream null;ServletOutputStream outputStream null;try {/** * 该方法会导致在部分环境中资源找不到的情况不推荐使用*///获得resource路径模板路径//String path Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource()).getPath() word/template.docx;// 读取Word模板//FileInputStream templateInputStream new FileInputStream(path);// 模板绑定数据//template XWPFTemplate.compile(templateInputStream).render(imageDownloadDate);// 从资源中加载Word模板try (InputStream templateInputStream getClass().getClassLoader().getResourceAsStream(word/template.docx)) {if (templateInputStream ! null) {// 模板绑定数据template XWPFTemplate.compile(templateInputStream).render(imageDownloadDate);} else {// 处理模板资源未找到的情况log.error(Word模板资源未找到);response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);return;}}//文件名String encodedFileName URLEncoder.encode(System.currentTimeMillis(), utf-8);//设置响应信息response.setHeader(Content-Disposition, attachment;filename encodedFileName .docx);response.setContentType(application/vnd.openxmlformats-officedocument.wordprocessingml.document);response.setCharacterEncoding(utf-8);outputStream response.getOutputStream();bufferedOutputStream new BufferedOutputStream(outputStream);template.write(bufferedOutputStream);//清空流bufferedOutputStream.flush();outputStream.flush();} catch (Exception e) {log.info(e.getMessage());response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);} finally {//关闭资源PoitlIOUtils.closeQuietlyMulti(template, bufferedOutputStream, outputStream);}}//根据base64编码获取图片格式信息private String getBase64Type(String base64) {byte[] b Base64.getDecoder().decode(base64);String type .png;if (0x424D ((b[0] 0xff) 8 | (b[1] 0xff))) {type .bmp;} else if (0x8950 ((b[0] 0xff) 8 | (b[1] 0xff))) {type .png;} else if (0xFFD8 ((b[0] 0xff) 8 | (b[1] 0xff))) {type .jpg;} else if (0x49492A00 ((b[0] 0xff) 24 | (b[1] 0xff) 16 | (b[2] 0xff) 8 | (b[3] 0xff))) {type .tif;}return type;}}五、Controller层实现 RestController RequestMapping(/test) Api(tags 获取商品图片) public class GetImageController {ResourceDownloadService downloadService;PostMapping(/download)ApiOperation(value 下载Word)void download(HttpServletResponse response,RequestBody DownloadDTO downloadDTO) throws IOException {//鉴权或其它处理//....downloadService.download(response,downloadDTO);}}
http://www.hkea.cn/news/14529832/

相关文章:

  • 怎么做qq二维码网站wordpress开启ssl变慢
  • php网站搬家软件青岛网站上排名
  • 如何自己做游戏网站上海尤安建筑设计股份有限公司
  • 那个外贸网站做的好电子商务网站建设与管理试题及答案
  • 伊川县住房和城乡建设厅网站网站建设术语
  • 揭阳网站建设策划方案通州富阳网站建设
  • 怎么攻击php做的网站吗博客网站 wordpress
  • 杭州外贸网站建设创新的盐城网站开发
  • ps做网站的视频黑帽seo软件
  • 设计网站多少费用多少重庆网站制作一般需要多少钱
  • 如何看出一个网站有做seo网站建设及安全管理
  • 网站开发的技术类型有哪些wordpress 专业模板下载
  • 给人做代工的网站固原市住房和城乡建设局网站
  • 苏州比较大的网站公司南宁企业网站设计公
  • 南昌网站建设讯息网站建设公司方维
  • 企业内部网站源码攀枝花城市建设网站
  • 怎样建立手机网站外贸网站流量
  • 网站的优点有哪些方面网站建设与网页设计是什么
  • 网站会员营销什么是单页面网站
  • 做网站和优化共多少钱搜狗推广管家
  • 网站建设工作室发展网页设计图片轮播效果
  • 湛江企业网站seo东莞智通人才网官方网站
  • 优质的南昌网站建设wordpress交友
  • 海口房产网站建设网站建设的定位是什么
  • 网站顶部深圳建筑工程交易服务中心网
  • 网站搭建需要多少钱智慧记免费官方下载
  • 酒店网站建设策划书怎么写wordpress域名变了迁移
  • 猎聘招聘官方网站舞蹈网站建设报价
  • 商业网站域名普洱市住房城乡建设局网站
  • 网站建设 邯郸网站制作游戏制作器