Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/namnv2496/springboot_jasperreport
Generate report by template jrxml
https://github.com/namnv2496/springboot_jasperreport
basic-programming demo-app docgen jasperreports spring-boot starter wordgenerator
Last synced: 7 days ago
JSON representation
Generate report by template jrxml
- Host: GitHub
- URL: https://github.com/namnv2496/springboot_jasperreport
- Owner: NamNV2496
- Created: 2022-12-25T12:12:03.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-14T11:44:43.000Z (about 1 year ago)
- Last Synced: 2024-11-09T02:35:18.203Z (2 months ago)
- Topics: basic-programming, demo-app, docgen, jasperreports, spring-boot, starter, wordgenerator
- Language: Java
- Homepage:
- Size: 2.74 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# jasper reports is a tool helping us to create file with template
![img.png](img/img_8.png)
![img_1.png](img/img_9.png)
# step 1: Create jrxml file![img.png](img/img.png)
choose a template
![img_1.png](img/img_1.png)
## step 2: config fonts if you want to display vietnamese
![img_2.png](img/img_2.png)
![img_3.png](img/img_3.png)
![img_4.png](img/img_4.png)
## Step 3: load jrxml file and compile it
![img_5.png](img/img_5.png)
## Step 4: fill data param and export to jasperPrint
![img_6.png](img/img_6.png)
## Step 5: export to file
![img_7.png](img/img_7.png)
curl
GET curl --location --request GET 'http://localhost:8080/test'
the output folder: `/out-put/`
example: `/out-put/test.pdf`
## About `JRBeanCollectionDataSource` fill in
The SQL query is used to retrieve data from the database when using a JRResultSetDataSource. When using a JRBeanCollectionDataSource, the data is already in memory, so there is no need to retrieve it from the database.
In the example I provided earlier, the queryString element in the employee.jrxml file specifies the SQL query to retrieve data from the employees table:
However, this query is not used when using a JRBeanCollectionDataSource. Instead, the JRBeanCollectionDataSource is passed to the fillReport method, which provides the data for the report.
```java
public byte[] generateReport(List employees) throws JRException {
Map parameters = new HashMap<>();
parameters.put("createdBy", "Bing");
parameters.put("createdDate", new Date());JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(employees);
``````xml
```
## with `JRResultSetDataSource` fill in
that way will access DB and get result and fill it into jrxml
```java
// Create a connection to the database
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase", "root", "password");// Create a statement to execute the SQL query
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM employees");// Create a JRResultSetDataSource using the ResultSet
JRResultSetDataSource dataSource = new JRResultSetDataSource(rs);
// Compile the report
JasperReport jasperReport = JasperCompileManager.compileReport("employee.jrxml");// Fill the report with data
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<>(), dataSource);
``````xml
```
# Gen HTML
```
curl --location 'http://localhost:8080/testHtml'
```