当前位置:网站首页>Basic usage and FAQs of jasperreport report report generation tool

Basic usage and FAQs of jasperreport report report generation tool

2022-06-22 14:12:00 Software testing Fairy

JasperReports Introduce

JasperReport Is a powerful 、 Flexible report generation tool , Able to display rich page content , And turn it into PDF、HTML perhaps XML Format , The library consists entirely of Java Write , Can be used in a variety of Java Applications , Very suitable Java Developers use it to generate reports .

Basic guidelines

New projects

Select template first , Here we choose the ordinary one directly A4 Templates .

This is used to set the file name and file path .

Here is the data source selection , I have created the database connection in advance , It will be used when fetching data in subsequent tests .

Here is the JasperReport Main interface , First, let's introduce the five main areas of the interface :

Area 1: Select a data source and project ;

Area 2: The content list used to display the report , All component information contained in the report will be displayed here ;

Area 3: This is the visual report content area , Include report styles , Report source code and preview generation ;

Area 4: Component list ;

Area 5: Attribute editing area .

Let's introduce some basic attribute names that need to be used :

Parameters: Report parameters , Usually filled by external incoming data ;

Fileds: Field , Generated by the associated database or entity class ;

Vareables: Variable , It can be used for some mathematical calculations .

Finally, several modules of report content are introduced :

Title( title ): Display only at the top of the first page of the entire report , The other pages do not display ;

Page Header( Header ): It will be displayed on every page of the whole report , The first page is in Title Below the area , Each subsequent page is displayed at the top of the page ;

Column Header( The column header ):Detail If a table is printed in ,Column Header Is the column header of each column in the table ;

Deatil( details ): Report content , Data can be displayed circularly ;

Column Footer( Column foot ):Detail If a table is printed in ,Column Footer Is the footer of each column in the table ;

Page Footer( The footer ): Each page of the entire report will be displayed at the bottom , Generally used to display page numbers ;

Summary( total ): Appears on the last page of the entire report , stay Detail Back , It is mainly used for total display of reports .

Start the pictorial table

This is the source code of the project , I need to get some data from the product table here ,queryString In the tag is the retrieval of the main item sql, Add it directly .

Add... Here sql Then I got the product ID Field , The following will be displayed in the report , So in FIelds The domain also adds ID_PRODUCT Properties of , You can add... Directly to your code , You can also add... In the main interface , Here's the picture , Right click directly Create Field, And then in the area 5 Class and name can be modified in .

What we're going to do is Static Text and “Text Field” Drag in Detail In the region , One is static text , One is used to put attributes .

double-click Text Field, You can select the attribute we just added ID_PRODUCT, And change the static text to product ID, Our report can be generated preliminarily .

You can see that it has been generated successfully , I only go to the top ten data here , Here is another example of filtering data through external input data , Use the nature of the investment VLU_INVEST_PROPERTY This field , First, add the external input parameter of this field , And then sql Add the statement corresponding to the filter .

Then add this field to the main interface , To generate a report, you can filter the data according to the external input field .

Here, the basic operation process of template file generation has been introduced , This time is .jxml file , And then you need to build become .jasper file , You can go to java Call in program jasper Relevant methods generate reports .

common problem

Error as shown in the figure

This error is usually caused by mismatching between page width and column length .

stay xml The beginning of the source code will columnWidth Change to ratio pageWidth Just a small piece .

Some tables in the main interface cannot be displayed

It is very likely that the overlap of tables leads to , After separation .

No query results

In the use of table After component , After external data input sql The query has no results .

Because the external input data is not passed to the sub query , You need to set the transfer of values .

As shown in the figure, the value of the main project can be passed to table in .

Memory leak or overflow

You can use an emulator to solve the problem , Recommended JRGzipVirtualizer Emulator , Memory leaks can be compressed to a minimum .

Last :

You can go to my personal number :atstudy-js, You can get one for free 10G Software Test Engineer interview classic documents . And the corresponding video learning tutorial is free to share ! It includes basic knowledge 、Linux necessary 、Mysql database 、 Caught tools 、 Interface testing tool 、 Test advanced -Python Programming 、Web automated testing 、APP automated testing 、 Interface automation testing 、 Testing advanced continuous integration 、 Test architecture development test framework 、 Performance test, etc .

These test data , For doing 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you !

原网站

版权声明
本文为[Software testing Fairy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221250491176.html