Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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