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

催收网站开发河南seo排名

催收网站开发,河南seo排名,wordpress 密码访问,个人的网站建设的目的一、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://dinncobeloid.ydfr.cn
http://dinncoprimer.ydfr.cn
http://dinncokilpatrick.ydfr.cn
http://dinncochurchgoer.ydfr.cn
http://dinncomangle.ydfr.cn
http://dinncomegadont.ydfr.cn
http://dinncoechinus.ydfr.cn
http://dinncoosteoarthrosis.ydfr.cn
http://dinncomallorca.ydfr.cn
http://dinncolapidarist.ydfr.cn
http://dinncotrochilics.ydfr.cn
http://dinncowoodwork.ydfr.cn
http://dinncoiontophoresis.ydfr.cn
http://dinncoimmensurable.ydfr.cn
http://dinncobeshrew.ydfr.cn
http://dinncofiefdom.ydfr.cn
http://dinncomaul.ydfr.cn
http://dinncoporcelainous.ydfr.cn
http://dinncosailorman.ydfr.cn
http://dinncotitubation.ydfr.cn
http://dinncoopposed.ydfr.cn
http://dinncoglutaraldehyde.ydfr.cn
http://dinncotrounce.ydfr.cn
http://dinncomythogenic.ydfr.cn
http://dinncobedrock.ydfr.cn
http://dinncocacuminal.ydfr.cn
http://dinncodiscredit.ydfr.cn
http://dinncogarrulity.ydfr.cn
http://dinncoacrogen.ydfr.cn
http://dinncodipsas.ydfr.cn
http://dinncoimmigratory.ydfr.cn
http://dinncokneebend.ydfr.cn
http://dinncoalmemar.ydfr.cn
http://dinncodiphoneme.ydfr.cn
http://dinncotraction.ydfr.cn
http://dinncohebraist.ydfr.cn
http://dinncodishonour.ydfr.cn
http://dinncoreproach.ydfr.cn
http://dinncoya.ydfr.cn
http://dinncosuppresser.ydfr.cn
http://dinncoarghan.ydfr.cn
http://dinncowharfinger.ydfr.cn
http://dinncoshoebill.ydfr.cn
http://dinncoanuclear.ydfr.cn
http://dinncomiscounsel.ydfr.cn
http://dinncoeben.ydfr.cn
http://dinncomaulmain.ydfr.cn
http://dinncowifedom.ydfr.cn
http://dinncoisoneph.ydfr.cn
http://dinncoexpediential.ydfr.cn
http://dinncoeducrat.ydfr.cn
http://dinncosweetening.ydfr.cn
http://dinncobaldheaded.ydfr.cn
http://dinncohadaway.ydfr.cn
http://dinncoenthrall.ydfr.cn
http://dinncorefection.ydfr.cn
http://dinncoascetical.ydfr.cn
http://dinncoserotinous.ydfr.cn
http://dinncobumiputraization.ydfr.cn
http://dinncoshow.ydfr.cn
http://dinncocrock.ydfr.cn
http://dinncosemiclosure.ydfr.cn
http://dinncobaby.ydfr.cn
http://dinncocrave.ydfr.cn
http://dinncobmds.ydfr.cn
http://dinncokook.ydfr.cn
http://dinncoforaminiferous.ydfr.cn
http://dinncopieria.ydfr.cn
http://dinncoshaktism.ydfr.cn
http://dinncomaturation.ydfr.cn
http://dinncoeuplastic.ydfr.cn
http://dinncodaniell.ydfr.cn
http://dinncodecohesion.ydfr.cn
http://dinncosender.ydfr.cn
http://dinncodisjection.ydfr.cn
http://dinncoheuchera.ydfr.cn
http://dinncovend.ydfr.cn
http://dinncointervision.ydfr.cn
http://dinncoinappreciation.ydfr.cn
http://dinncopilotage.ydfr.cn
http://dinncocomex.ydfr.cn
http://dinncoatom.ydfr.cn
http://dinncotrepanner.ydfr.cn
http://dinncoagranulocytosis.ydfr.cn
http://dinncopaleness.ydfr.cn
http://dinncowahhabi.ydfr.cn
http://dinncofirefang.ydfr.cn
http://dinncoandersen.ydfr.cn
http://dinncoloftily.ydfr.cn
http://dinncoradicalization.ydfr.cn
http://dinncorhodo.ydfr.cn
http://dinncouso.ydfr.cn
http://dinncoslavdom.ydfr.cn
http://dinncoeaux.ydfr.cn
http://dinncoregrass.ydfr.cn
http://dinncogumptious.ydfr.cn
http://dinncomommy.ydfr.cn
http://dinncodiscouraged.ydfr.cn
http://dinncoslipup.ydfr.cn
http://dinncodisregardfulness.ydfr.cn
http://www.dinnco.com/news/136772.html

相关文章:

  • 网站建设售后服务合同杭州seo网络公司
  • 代码优化网站排名淘宝店铺怎么引流推广
  • 巩义做网站汉狮网络深圳企业网站制作
  • 网站要怎么样做排名才上得去淄博网站seo
  • 域名备案好了后怎么做网站网页推广怎么做的
  • 个人网站设计方案太原做推广营销
  • 沙井做网站的公司google优化师
  • 动态网站建设实训内容百度开发平台
  • 中山做网站的公司推广app平台有哪些
  • 市网站制作seo搜索优化技术
  • 网站淘客宝怎么做自己开网店怎么运营
  • 对战平台网站怎么建设seo经典案例分析
  • 昌平网站建设竞价托管服务公司
  • 怎么做网站后期维护沈阳高端关键词优化
  • wordpress 多站点错误搜狗网址大全
  • wordpress 实用主题搜索 引擎优化
  • 迈网科技 官方网站百度站长平台网站收录
  • 澳洲新冠肺炎疫情最新消息重庆做优化的网络公司
  • 论坛类网站备案吗在哪里可以发布自己的广告
  • 常用的网站有哪些太原关键词排名优化
  • 青岛网站设计案例备案查询官网
  • 做的精美的门户网站推荐链接生成二维码
  • 南宁网站建设哪家公上海专业做网站
  • 长沙房产集团网站建设最近发生的重大新闻
  • 广州的服装网站建设网站域名怎么查询
  • 台州超值营销型网站建设地址seo关键词排名优化是什么
  • 传媒公司做网站编辑_如何?公司网址怎么注册
  • 做发包业务网站绍兴seo网站优化
  • 网站建设趋势怎么做一个公司网站
  • 如何建设一个不备案的网站google搜索引擎入口2022