In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how SpringBoot integrates EasyExcel". In daily operation, I believe many people have doubts about how SpringBoot integrates EasyExcel. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how SpringBoot integrates EasyExcel". Next, please follow the editor to study!
Why use EasyExcel?
As both apache poi and jxl,excelPOI have a serious problem, that is, they consume a lot of memory, especially when dealing with a large amount of data, slow speed and sometimes anomalies occur, so switch to easyExcel developed by Ali is more reliable, its official recommendation for less than 1000 lines using the original poi write method to read and write, but in more than 1000 lines of data, the use of a row-by-line parsing scheme, so as to avoid memory overflow.
Introduction to 1.EasyExcel
The well-known frameworks for Java domain parsing and generating Excel are Apache poi, jxl and so on. But they all have a serious problem is that they consume a lot of memory. If your system concurrency is not large, it may be OK, but once the concurrency comes up, there will be frequent full gc of OOM or JVM.
EasyExcel is an open source excel processing framework of Alibaba, which is famous for its easy to use and memory saving. The main reason why EasyExcel can greatly reduce the memory footprint is that instead of loading all the file data into memory at once when parsing Excel, it reads the data from one row on disk and parses it one by one.
EasyExcel adopts the parsing mode of one line, and notifies the processing of the parsing result of one line in observer mode (AnalysisEventListener)
two。 Using EasyExcel implementation to write 2.1 to create entity classes
Create an entity class corresponding to Excel
/ * * @ author xppll * @ date, 2021-12-3 10:05 * / @ Datapublic class DemoData {/ / set the name of the excel header, and index represents the corresponding column @ ExcelProperty (value = "student number", index = 0) private Integer sno; @ ExcelProperty (value = "student name", index = 1) private String sname;}
ExcelProperty: specifies which column in the excel corresponds to the current field. It can be matched by name or Index. Of course, you don't have to write it. The default first field is index=0, and so on.
2.2 Test and write Excel/** * @ author xppll * @ date 10:08 on 2021-12-3 * / public class TestWriteExcel {public static void main (String [] args) {/ / implement the excel write operation / / 1. Set the address to write to the folder and the name of the excel file String fileName = "D:\\ write.xlsx"; / / 2. Call the method in easyexcel to realize the write operation / / input: the path where the file is stored + the corresponding entity class class EasyExcel.write (fileName, DemoData.class) .sheet ("student list") .doWrite (getData ());} / / create method to return list collection (test data) private static List getData () {List list = new ArrayList (); for (int I = 0; I)
< 10; i++) { DemoData data = new DemoData(); data.setSno(i); data.setSname("lucy" + i); list.add(data); } return list; }} 结果如下The Excel template is as follows
The database data after upload is as follows
At this point, the study on "how SpringBoot integrates EasyExcel" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.