The first code review learned of the problem (non-I)

Demand Description: Exporting a report from the database, the header of the report is more complex, given the start time and end time, export all of the data within this section

Original code: custom tools, began to write a blank table, defines a set of array header, and then to write the header, then condition query data written to the file, exported directly to the response output stream to complete the download .

Pointed out the problem: write from scratch a waste of time, color table height and width of the head and other styles more complex, will take up a lot of code, it is better to place a template file in the project directory, there is only the header data,

Every time you download, we direct copy of the file, use uuid uniquely named, and then write the exported data to a file copy, the last output file to the response stream, do not forget to delete the file after download so as not to take up too much space.

We need to place special attention:

First, be sure to copy the file to do the operation and the file name can not be repeated, prevent concurrent modifications.

Second, do not forget to delete the files after the download is complete

Third, the large amount of data, paging query should be written to the file, preventing take up too much memory.

 

Guess you like

Origin www.cnblogs.com/helloworldmybokeyuan/p/11317064.html