So, what is DynamicJasper? DynamicJasper is a superior version of JasperReports but with the added capability of the report being generated at runtime. Not to mention it is very fast, very customizable and very easy to implement.
What we’ll be covering in this article, is how to create reports using DynamicJasper at runtime in Java SpringBoot using Java Model Class as its Data Source. For the example in this article, I have already connected my JavaSpring project with MySQL database and have already created API CRUD services in it. Which is all the basic stuff. Don’t worry, I have uploaded the project on to my GitHub account and have shared the link below.
Let me show you the database and the model class with all the properties. As shown in the picture below, here is a basic employee table with just a few records and I will be populating them in the report further ahead with the employee model class as the Data Source.
There it is, a traditional employee table with the traditional columns as seen above. Next will make a Java spring boot project from Spring Initializr. Which you should be already familiar with if you’ve used SpringBoot before. I’m still going to attach a picture just to show how to set up the basic layout for creating the project. for creating the project
After this, you can click on generate button which will download the project open up the project in any of your favorite editors or an IDE whereas I am going to use IntelliJ IDE for this project. After opening the project, I have already made all the necessary controller services and model classes and I’ve already added the configuration for connecting it to my local MySQL Server. you can do the same cause that is all very basic if you’re having any issues, you can always download the project, I have already uploaded this project onto my GitHub profile The link for which I will be sharing is at the bottom of this article.
So, the first thing is that we’re going to tackle an upcoming problem that we’ll face when implementing a dynamic Jasper third-party library. So, let’s open up “DynamicJasperReportApplication.java” file, and REPLACE the old code with the new one shown below:
Before Changes
After Changes
OK the next step is one of the crucial ones, it’s to add the dependency in the pom.xml file. There shall be two dependencies added. One would be simple “jasperreports” and the other would be “dynamicJasper”. So let’s open pom dot XML file and add the following dependencies:
OK so now what we need to do is to make a new API endpoint in the controller directory, so that whenever a specific URL is searched, it will reach this controller which would take it further on. The function would be like this:
What’s exactly happening in this function is that it’s fetching the response from another function, which is inside the service class, and it’s returning that response to the user. Now let’s see what’s exactly happening in that function in the service class because that’s where all the report generation code is taking place.
function inside the service class:
So, what’s exactly going on here?
So, inside this function on line 85 it’s for three fetching all the data from the database table “employee” and bring them all in a list object called “allEmployeeList”.
Next, it’s creating a FastReportBuilder object which contains all the functionality and properties that could be attached to the report during runtime, such as adding column, adding width, adding title and more. In here we’ve added five columns, whose name matches exactly from our Model class properties, then we’re also adding a title, a subtitle and then finally building it.
Moving on to line 100, we need to specify the data source for the Jasper report and here we’ve used “JRBeanCollectionDataSource” which would essentially take in the entire model class of employee. It will compare the Model class property names with the names mentioned in the FastReportBuilder object when we were creating new columns. And then finally it will print the report, following line 102. So, let’s run the project and open up Postman for testing.
Testing With POSTMAN
The report after generating would look something like this:
And that’s a wrap!
I hope you all work clear on the steps and now have a clear view on how to generate a dynamic Jasper report using models last in Java spring good, fetching data from MySQL database. Please leave a comment and share this article with others. Have a great one!
Project File
Recent Posts
- Šikovná_strategie_fortuna_nabízí_pestré_sázky_a_bonusy_pro_každého_hrá
- Absorbția_riscurilor_financiare_și_fortuna_acumulată_prin_investiții_intelig
- Analiza_skuteczności_strategii_finansowych_z_uwzględnieniem_fortuna_i_długote
- LuckyLouis Casino mobilapp: spil nemt og hurtigt på farten
- Úspešné_stratégie_a_možnosti_zisku_s_fortuna_pre_inteligentných_stávkarov
Recent Comments
Archives
- June 2026
- May 2026
- October 2025
- October 2024
- September 2024
- August 2024
- June 2024
- January 2024
- November 2023
- October 2023
- September 2023
- August 2023
- June 2023
- May 2023
- March 2023
- December 2022
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
Categories
- 21
- aks 1 en
- aks 1 pl
- aks 18
- aks 28
- aks 31
- Angular
- AWS
- Backend Development
- Big Data
- Blog
- Cloud
- crypto 01
- crypto 05
- crypto 15
- crypto 19 en
- crypto 20
- crypto 20.05
- crypto 21.05
- crypto 29
- crypto 5
- Database
- Deployment
- DevOps
- Docker
- fi
- Frontend Development
- GitHub
- Google Cloud Platform
- hu
- Installations
- it
- Java
- JavaScript
- Linux
- MySQL
- Networking
- News
- nl
- no
- NodeJS
- Online casino
- Operating System
- Post
- public
- Python
- Python Flask
- Report
- Security
- Server
- SpringBoot
- Subdomain
- sushicasino 13
- TypeScript
- Uncategorized
- VSCode
- Webhosting
- WordPress
- Στοιχηματικές
Search
Recent Post
Šikovná_strategie_fortuna_nabízí_pestré_sázky_a_bonusy_pro_každého_hrá
- 27 June, 2026
- 10 min read
Absorbția_riscurilor_financiare_și_fortuna_acumulată_prin_investiții_intelig
- 27 June, 2026
- 8 min read
Analiza_skuteczności_strategii_finansowych_z_uwzględnieniem_fortuna_i_długote
- 27 June, 2026
- 8 min read