Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Troubleshooting sample analysis using EasyPoi

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

What this article shares with you is an example analysis of the use of EasyPoi for censorship. The editor thinks it is very practical, so I share it with you for study. I hope you can get something after reading this article.

Troubleshoot the use of EasyPoi:

/ / this is to call a method of indexScoreMonitoringService to return DTO. This DTO encapsulates the data List scoreCollinearityParentClassDTOS = indexScoreMonitoringService.scoreCollinearity (ratingModelReportQuery, indexScoreIdsList, 1) that needs to be exported from excel; / / calls the company's unified packaged EasyPoiUtil utility class to download the excel file EasyPoiUtil.exportExcel (scoreCollinearityParentClassDTOS, null, EasyPoiUtil.CHART_NAME [cid], ScoreCollinearityExcelDTO.class, EasyPoiUtil.CHART_ NAMEcid] + ".xls", response).

Here is a description of the exportExcel method in this utility class

/ * function description: complex export Excel, including file name and table name, do not create header * * @ author yan * @ date 14:11 on 2019-8-5 * @ param list exported entity class * @ param title header name * @ param sheetName sheet table name * @ param pojoClass mapped entity class * @ param fileName * @ param response * @ return * /

The code related to ScoreCollinearityParentClassDTO will be posted below.

Private static final long serialVersionUID = 4575184647737532340L (name = "collinear", width = 40, orderNum= "4") public String collinearity;//. Omit the following other code that generates set and get.

In addition, my colleague said that he actually used ScoreCollinearityExcelDTO, a subclass of ScoreCollinearityParentClassDTO, when constructing DTO, so I posted ScoreCollinearityExcelDTO as well. Specific package DTO will not be posted. The following is the relevant code about ScoreCollinearityExcelDTO

@ Excel (name = "date", width = 40) private String month;@Excel (name = "model name", width = 40) private String modelName;@Excel (name = "module name A ~ indicator name A-module name B~ indicator name B", width = 40) private String ModuleNameIndexName;//. Omit the following other code that generates set and get.

For the record here, when my colleague was troubleshooting the problem in advance, he found that the export had only a list of values of the parent class, so he modified the code locally, returned a collection of subclasses, and then reported a null pointer exception. So in order to be consistent with his native code, I am now modifying the code locally. I will not post the specific modified code. Is to modify the Service that encapsulates DTO to return the subclass collection, and then accept it with the subclass collection.

two。 Solve the problem

The problem is described above. Since there is not much code, I will first check what is wrong with the code with the naked eye. Finally, it is found that an attribute definition in ScoreCollinearityExcelDTO does not conform to the specification.

The initials were capitalized. Maybe my colleague copied it somewhere and forgot to modify it. I'll change this place to lowercase first. Then I tested myself and found that the problem had been solved. Ha ha. It feels so good. So I asked my colleagues to change the place, submit the code, solve the problem first, and don't get stuck here.

3. Track the source code and analyze the reason

The problem is solved. But why? We can't just be confused, solve the problem, and let it go. Even if you were busy at work at that time, you should make a note. Afterwards, we should also analyze the problem and find out where the root of the problem lies. I know why. So I started the process of looking at the easypoi source code.

I am now restoring the code locally. Then debug prints out the exception information. Found that it is not a null pointer problem ah, embarrassed.

And the error report is also very detailed, describing the field names. Maybe my side is different from his side.

Obviously, this acquisition method has not been obtained, which is null. Let's make a breakpoint here to debug. It is found that it is indeed null

View getMethods

A map,key is returned as moduleNameIndexName, but the input is ModuleNameIndexName. Of course, it cannot be found. So let's take a look at how this getMethods is encapsulated. The following is the relevant source code that I have been looking for, and I have marked out the key points.

The bottom layer of easypoi is encapsulated into the Map collection through all the get methods in the past. Key removes the method name and writes the initials as key after removing get. So getModuleNameIndexName-> moduleNameIndexName

When you get it, it is obtained through the property name. Here, whether it is moduleNameIndexName or ModuleNameIndexName, the generated get method is the same. So it leads to different problems.

The above is the sample analysis of the use of EasyPoi. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report