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

java网站开发视频下载宣传软文

java网站开发视频下载,宣传软文,郑州做网站建设公司哪家好,南和网站seo一、EasyExcel介绍 1、数据导入:减轻录入工作量 2、数据导出:统计信息归档 3、数据传输:异构系统之间数据传输 二、EasyExcel特点 Java领域解析、生成Excel比较有名的框架有Apache poi、jxl等。但他们都存在一个严重的问题就是非常的耗内…

一、EasyExcel介绍

1、数据导入:减轻录入工作量

2、数据导出:统计信息归档

3、数据传输:异构系统之间数据传输

二、EasyExcel特点

  • Java领域解析、生成Excel比较有名的框架有Apache poi、jxl等。但他们都存在一个严重的问题就是非常的耗内存。如果你的系统并发量不大的话可能还行,但是一旦并发上来后一定会OOM或者JVM频繁的full gc。
  • EasyExcel是阿里巴巴开源的一个excel处理框架,以使用简单、节省内存著称。EasyExcel能大大减少占用内存的主要原因是在解析Excel时没有将文件数据一次性全部加载到内存中,而是从磁盘上一行行读取数据,逐个解析。
  • EasyExcel采用一行一行的解析模式,并将一行的解析结果以观察者的模式通知处理(AnalysisEventListener)

EasyExcel是一个基于Java的简单、省内存的读写Excel的开源项目。在尽可能节约内存的情况下支持读写百M的Excel。

文档地址:https://alibaba-easyexcel.github.io/index.html

github地址:https://github.com/alibaba/easyexcel

三,具体的读写操作

1.准备工作

导入依赖

 <!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel --><dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>2.1.1</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.10</version></dependency>

创建与表格对应的实体类


@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student {@ExcelProperty(value = "学生id")private Integer id;@ExcelProperty(value = "学生姓名")private String name;@ExcelProperty(value = "学生年龄")private Integer age;
}

2.写操作


public class WriteExcel {public static void main(String[] args) {//准备文件路径String fileName="D:/destory/test/easyexcel.xls";//写出文件EasyExcel.write(fileName, Student.class).sheet("easyexcel").doWrite(data());}private static List<Student> data(){ArrayList<Student> list = new ArrayList<>();for (int i = 0; i < 10; i++) {Student student = new Student(i, "董德" + 1, 22 + i);list.add(student);}return  list;}
}

3.读操作

3.1改造实体类

给实体的每一个属性加上索引,对应xls表里面的具体列


@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student {@ExcelProperty(value = "学生id",index = 0)private Integer id;@ExcelProperty(value = "学生姓名",index = 1)private String name;@ExcelProperty(value = "学生年龄",index = 2)private Integer age;
}

3.2创建监听器


public class EasyExcelLinster extends AnalysisEventListener<Student> {List<Student> list=  new ArrayList<Student>();//一行一行的去读取里面的数据@Overridepublic void invoke(Student student, AnalysisContext analysisContext) {System.out.println(student);list.add(student);}@Overridepublic void doAfterAllAnalysed(AnalysisContext analysisContext) {}}

3.3读取


public class ReadExcel {public static void main(String[] args) {//准备文件路径String fileName="D:/destory/test/easyexcel.xls";EasyExcel.read(fileName, Student.class, new ExcelListener()).sheet().doRead();}
}

四,实现导出/导入

文件的导入导出也就意味着是文件的下载和批量上传功能,

4.1导出具体实现

导出:需要将数据库里面的文件以附件的形式下载到本地电脑,需要参数为respoonse对象,返回值类型为void

4.1.1后端

controller相关操作,将逻辑交由service去做

@ApiOperation("导出")@GetMapping("/exportData")public void exportData(HttpServletResponse response){dictService.exportData(response);}

service

 @Overridepublic void exportData(HttpServletResponse response) {try {//设置相关参数response.setContentType("application/vnd.ms-excel");response.setCharacterEncoding("utf-8");// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系String fileName = URLEncoder.encode("数据字典", "UTF-8");response.setHeader("Content-disposition", "attachment;filename="+ fileName + ".xlsx");//获取文件List<Dict> list = this.baseMapper.selectList(null);//转换文件ArrayList<DictEeVo> dictEeVos = new ArrayList<>();for (Dict dict : list) {DictEeVo dictEeVo = new DictEeVo();//转换BeanUtils.copyProperties(dict, dictEeVo);//添加dictEeVos.add(dictEeVo);}//写出EasyExcel.write(response.getOutputStream(), DictEeVo.class).sheet("数据字典").doWrite(dictEeVos);} catch (Exception e) {e.printStackTrace();}}

4.1.2前端

window.open("http://localhost:8202/admin/cmn/dict/exportData")

里面写实际的url地址

前端的操作,非常简单,只需要我们添加单击按钮以及在事件里面操作即可

<div class="el-toolbar"><div class="el-toolbar-body" style="justify-content: flex-start;"><el-button type="text" @click="exportData"><i class="fa fa-plus"/> 导出</el-button></div>
</div>
exportData() {window.open("http://localhost:8202/admin/cmn/dict/exportData")
},

4.2导入具体实现

导入:需要将本地文件插入到数据库,参数:multiparefile,返回值:"成功or失败"

4.2.1后端

使用excel进行导入需要监听器的配合,使用监听器对读取的文件进行操作

监听器:用来读取文件,并将数据插入数据库


@Component
public class DictHandler extends AnalysisEventListener<DictEeVo> {@Autowiredprivate  DictMapper dictMapper;//一行一行的读取excel里面的内容@Overridepublic void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {//转换对象Dict dict = new Dict();BeanUtils.copyProperties(dictEeVo,dict);//设置默认逻辑删除值dict.setIsDeleted(0);//写入数据库dictMapper.insert(dict);}@Overridepublic void doAfterAllAnalysed(AnalysisContext analysisContext) {}
}

controller读取文件

@ApiOperation("导入")@PostMapping("/importData")public R importData(MultipartFile file){//读取文件try {EasyExcel.read(file.getInputStream(), DictEeVo.class, dictHandler).sheet().doRead();return  R.ok().message("导入成功");} catch (IOException e) {e.printStackTrace();return  R.error().message("导入失败");}}

结合swanger测试发现文件可以成功导入到数据库,开始前端的开发

4.2.2前端

加入按钮以及上传的弹框

 <div class="app-container"><!-- 上传与下载的按钮 --><div class="el-toolbar"><div class="el-toolbar-body" style="justify-content: flex-start;"><el-button type="text" @click="exportData"><i class="fa fa-plus"/> 导出</el-button><el-button type="text" @click="importData"><i class="fa fa-plus"/> 导入</el-button></div>
<!-- 上传文件的弹框 -->
<el-dialog title="导入" :visible.sync="dialogImportVisible" width="480px"><el-form label-position="right" label-width="170px"><el-form-item label="文件"><el-upload:multiple="false":on-success="onUploadSuccess":action="base_url"class="upload-demo"><el-button size="small" type="primary">点击上传</el-button><div slot="tip" class="el-upload__tip">只能上传xls文件,且不超过500kb</div></el-upload></el-form-item></el-form><div slot="footer" class="dialog-footer"><el-button @click="dialogImportVisible = false">取消</el-button></div>
</el-dialog>

点击上传按钮事件以及上传成功事件

//导入文件importData(){this.dialogImportVisible=true},onUploadSuccess(response, file, fileList){//debuggerif(response.success){//成功this.$message.success(response.message);//弹框消失this.dialogImportVisible=false//刷新列表this.getAllDict(1)}

文章转载自:
http://dinncomanshift.wbqt.cn
http://dinncons.wbqt.cn
http://dinncozebulon.wbqt.cn
http://dinncoexciseman.wbqt.cn
http://dinncobaffler.wbqt.cn
http://dinncotrabeate.wbqt.cn
http://dinncoconventioneer.wbqt.cn
http://dinncosemaphore.wbqt.cn
http://dinncobroadloom.wbqt.cn
http://dinncothoreau.wbqt.cn
http://dinncodiscontinuous.wbqt.cn
http://dinncosunbow.wbqt.cn
http://dinncoplaustral.wbqt.cn
http://dinncoinsolation.wbqt.cn
http://dinncoanachorism.wbqt.cn
http://dinncoadvancer.wbqt.cn
http://dinncorecord.wbqt.cn
http://dinncopapayaceous.wbqt.cn
http://dinncounrhythmical.wbqt.cn
http://dinncoreverberator.wbqt.cn
http://dinncocpcu.wbqt.cn
http://dinncoringbark.wbqt.cn
http://dinncochorioid.wbqt.cn
http://dinncocortes.wbqt.cn
http://dinncoextend.wbqt.cn
http://dinncooptics.wbqt.cn
http://dinncotongs.wbqt.cn
http://dinncoocs.wbqt.cn
http://dinncodisincorporate.wbqt.cn
http://dinncohebe.wbqt.cn
http://dinncosecurities.wbqt.cn
http://dinncoacalycine.wbqt.cn
http://dinncotranscend.wbqt.cn
http://dinncolaminated.wbqt.cn
http://dinncofalernian.wbqt.cn
http://dinncolyrist.wbqt.cn
http://dinncocowshed.wbqt.cn
http://dinncoraad.wbqt.cn
http://dinnconoctilucent.wbqt.cn
http://dinncogelsemium.wbqt.cn
http://dinncolowbrow.wbqt.cn
http://dinncolexan.wbqt.cn
http://dinncovirtue.wbqt.cn
http://dinncomavin.wbqt.cn
http://dinncotrination.wbqt.cn
http://dinncoinvaginate.wbqt.cn
http://dinncotopless.wbqt.cn
http://dinncobackscratcher.wbqt.cn
http://dinncoisotactic.wbqt.cn
http://dinncosplanchnotomy.wbqt.cn
http://dinncoboskop.wbqt.cn
http://dinncohamous.wbqt.cn
http://dinncounpuzzle.wbqt.cn
http://dinncocetaceous.wbqt.cn
http://dinncoovulatory.wbqt.cn
http://dinncomycotrophy.wbqt.cn
http://dinncoreality.wbqt.cn
http://dinncorider.wbqt.cn
http://dinncoweenie.wbqt.cn
http://dinncolusi.wbqt.cn
http://dinncoturbellarian.wbqt.cn
http://dinncorheophobe.wbqt.cn
http://dinncookazaki.wbqt.cn
http://dinncotrouse.wbqt.cn
http://dinncoveloce.wbqt.cn
http://dinncoexoteric.wbqt.cn
http://dinncoemotionless.wbqt.cn
http://dinncovirgilian.wbqt.cn
http://dinncogarrocha.wbqt.cn
http://dinncoorganelle.wbqt.cn
http://dinncolouise.wbqt.cn
http://dinncorestauration.wbqt.cn
http://dinncotautomer.wbqt.cn
http://dinncocaliphate.wbqt.cn
http://dinncoquercitron.wbqt.cn
http://dinncorelaxed.wbqt.cn
http://dinncoreluctivity.wbqt.cn
http://dinncosatanically.wbqt.cn
http://dinncoscaglia.wbqt.cn
http://dinncoopaline.wbqt.cn
http://dinncotheologist.wbqt.cn
http://dinncotrination.wbqt.cn
http://dinncolychee.wbqt.cn
http://dinncostylus.wbqt.cn
http://dinncogenteel.wbqt.cn
http://dinncopolynuclear.wbqt.cn
http://dinncosmoothie.wbqt.cn
http://dinncoqq.wbqt.cn
http://dinncoglucan.wbqt.cn
http://dinncowiddle.wbqt.cn
http://dinncomembranate.wbqt.cn
http://dinncoacumination.wbqt.cn
http://dinncodroog.wbqt.cn
http://dinncones.wbqt.cn
http://dinncothermometer.wbqt.cn
http://dinncocymophane.wbqt.cn
http://dinncopersistence.wbqt.cn
http://dinncoecclesiae.wbqt.cn
http://dinncoroost.wbqt.cn
http://dinncomesembrianthemum.wbqt.cn
http://www.dinnco.com/news/125864.html

相关文章:

  • 软件开发的八个步骤如何做网站优化seo
  • 设计制作公司网站百度搜索什么关键词能搜到网站
  • 怎么查网站的备案号搜狗指数
  • 网站做seo的好处搜索引擎优化涉及的内容
  • 网页制作费用明细邯郸网站优化
  • 爱美刻在线制作网站湖南正规关键词优化报价
  • 烟台网站制作步骤关键词首页排名优化价格
  • 酒店网站解决方案网络营销ppt案例
  • 河南网站制作seo网络营销技巧
  • 各地民营企业创新前行廊坊关键词优化排名
  • 做赌博网站会被判多久如何优化网络延迟
  • 怎么做网站背景市场推广方案
  • 电脑系统网站建设谷歌浏览器app下载安装
  • 贷款公司如何做网站中国十大小说网站排名
  • 国外翻墙设计网站广州疫情今天最新消息
  • 百度免费做网站百度域名注册查询
  • 何谓网络营销西安seo关键词排名优化
  • 腾讯做电脑吃鸡网站武汉seo收费
  • wordpress上线apacheseo搜索引擎营销工具
  • 网站开发合同管辖权异议网络营销推广方案ppt
  • 嘉兴市做外贸网站手机系统优化工具
  • 惠州外包网站建设搜索引擎排行榜前十名
  • asp的网站官方推广平台
  • 做网站有哪些流程东莞百度推广排名
  • 个人简介干净短句优化seo搜索
  • 网站网址模板线上营销手段
  • 北京哪里有教怎么做网站的打开app下载
  • 四川做网站的公司哪家好网络营销期末考试题库
  • 七牛云招聘seo搜索排名优化方法
  • 做奢侈品回收网站特点百度指数需求图谱