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: 25 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 (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-14T11:44:43.000Z (over 2 years ago)
- Last Synced: 2025-02-22T06:11:56.651Z (over 1 year 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


# step 1: Create jrxml file

choose a template

## step 2: config fonts if you want to display vietnamese



## Step 3: load jrxml file and compile it

## Step 4: fill data param and export to jasperPrint

## Step 5: export to file

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'
```