Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/birddevelper/salmos-report-spring-boot-starter
A useful simple to use spring-boot library that help you to build beautiful html table, xml document, PDF or any other formats with very specific features from sql or list of objects
https://github.com/birddevelper/salmos-report-spring-boot-starter
generator hibernate html java jdbc jdbctemplate pdf report reportgenerator spring spring-boot xls xml
Last synced: 21 days ago
JSON representation
A useful simple to use spring-boot library that help you to build beautiful html table, xml document, PDF or any other formats with very specific features from sql or list of objects
- Host: GitHub
- URL: https://github.com/birddevelper/salmos-report-spring-boot-starter
- Owner: birddevelper
- License: apache-2.0
- Created: 2021-09-29T14:34:49.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-12T19:55:51.000Z (over 1 year ago)
- Last Synced: 2024-04-17T19:19:23.481Z (7 months ago)
- Topics: generator, hibernate, html, java, jdbc, jdbctemplate, pdf, report, reportgenerator, spring, spring-boot, xls, xml
- Language: Java
- Homepage:
- Size: 224 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
What is SalmosReport
======
[![Maven Central](https://img.shields.io/maven-central/v/io.github.birddevelper/salmos-report-spring-boot-starter.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.github.birddevelper%22%20AND%20a:%22salmos-report-spring-boot-starter%22)SalmosReport is a spring boot library that facilitates the creation of HTML reporting tables and documents in various formats such as HTML, XML, PDF, and custom formats from SQL queries, arrays, and lists. Presently, the tool can generate HTML, XML, PDF documents, and customized format reports.other custom formats.
![Salmos Report](https://raw.githubusercontent.com/birddevelper/salmos-report-spring-boot-starter/master/salmosReport_SQL_Hibernate.jpg)
### Features
* Read data from List of Objects and Entities
* Read data from database by sql query
* Aggregation functions (Sum, Average, Count)
* Generate HTML Report
* Generate XML document
* Generate PDF document
* Generate custom structure report
* Generate TEXT file from report
* Css Classes for HTML report
* Embedded Css Style for HTML report### Getting started
Current Version of the plugin is 2.1.0
Gradle :
```shell
implementation 'io.github.birddevelper:salmos-report-spring-boot-starter:2.1.0'
```Maven :
```shellio.github.birddevelper
salmos-report-spring-boot-starter
2.1.0```
### Usage
There exist 3 classes in this plugin to make amazing things for you.
* HtmlReportMaker : A class that generates HTML table from records retrieved from sql query or from list of objects.
* XmlReportMaker : A class that generates XML document from records retrieved from sql query or from list of objects.
* GeneralReportMaker : This class generates output in any given structure and format from sql query or list of objects.#### HtmlReportMaker Sample code
```java
import io.github.birddevelper.salmos.HtmlReportMaker;
import io.github.birddevelper.salmos.setting.HtmlReportTemplate;
import io.github.birddevelper.salmos.setting.SummaryType;@Service
public class ReportService {@Autowired
DataSource dataSource;public String generateReport() {
// Creating instance of HtmlReportMaker
HtmlReportMaker hrm = new HtmlReportMaker(dataSource);
// specify columns of data that must be summarized in table footer row
hrm.addSummaryColumn("Age", SummaryType.AVERAGE);
hrm.addSummaryColumn("Salary", SummaryType.SUM);
// template specifies the report table appearance
HtmlReportTemplate myTemplate = new HtmlReportTemplate();
myTemplate.setTableCssClass("tblReport");
myTemplate.setEvenRowCssClass("myEvensRow");
myTemplate.setOddRowCssClass("myOddsRow");
myTemplate.setHeaderRowCssClass("myheader");
myTemplate.setRightToLeft(true);
myTemplate.setRowIndexHeader("#");
myTemplate.setRowIndexVisible(true);
hrm.setTemplate(myTemplate);
// summary section numbers decimal point setting
hrm.setSummaryDecimalPrecision(1);
// summary section numbers seperated by comma
hrm.setSummaryCommaSeperatedNumbers(true);
// show row's index
hrm.isRowIndexVisible(true);
// set the query retrieving data from database
hrm.setSqlQuery("select fullname as 'Name', age as 'Age', salary as 'Salary' from chamber limit 0,10");
return hrm.generate();
}
}
```#### XmlReportMaker Sample Code
```java
import io.github.birddevelper.salmos.XmlReportMaker;
import io.github.birddevelper.salmos.setting.SummaryType;
import io.github.birddevelper.salmos.setting.XmlReportElementType;
@Service
public class ReportService {@Autowired
DataSource dataSource;public String generateXMLReport() {
// Creating instance of XmlReportMaker
XmlReportMaker xrm = new XmlReportMaker(dataSource);// specify columns of data that must be summarized (they will put in root element as attribute)
xrm.addSummaryColumn("Age", SummaryType.AVERAGE);
xrm.addSummaryColumn("Salary", SummaryType.SUM);// summary section numbers decimal point setting
xrm.setSummaryDecimalPrecision(0);
xrm.setRootElementName("Persons");
xrm.setChildElementName("person");
// this line set the generator to put row data in attributes of row element
xrm.setXmlReportElementType(XmlReportElementType.RecordColumnAsElementAttribute);
// set the query retrieving data from database
xrm.setSqlQuery("select fullname as 'Name', age as 'Age', salary as 'Salary' from chamber limit 0,10");
return xrm.generate();
}
}
```#### GeneralReportMaker Sample code
```java
import org.log.carvan.utils.GeneralReportMaker;
import io.github.birddevelper.salmos.setting.SummaryType;@Service
public class ReportService {@Autowired
DataSource dataSource;public String generateUniversalReport() {
GeneralReportMaker grm = new GeneralReportMaker(dataSource);
// load template from file located in resources
grm.loadTemplateBodyFromFile("templates/salmosTemplates/template1.html");// set the query retrieving data from database
grm.setSqlQuery("select fullname as 'Name', age as 'Age', salary as 'Salary' from chamber limit 0,10");// specify columns of data that must be summarized
grm.addSummaryColumn("Age", SummaryType.AVERAGE);
grm.addSummaryColumn("Salary", SummaryType.SUM);// set footer template with String (to have a column summary in footer, you should use ::[column name]Summary in template
grm.setTemplateFooter("CityCount >> ::AgeSummary ---- Capacity Average >> ::SalarySummary
");
return grm.generate(); // return String containing the produced report}
}
```### Generate PDF report
```java
import io.github.birddevelper.salmos.HtmlReportMaker;
import io.github.birddevelper.salmos.setting.HtmlReportTemplate;
import io.github.birddevelper.salmos.setting.SummaryType;@Service
public class ReportService {@Autowired
DataSource dataSource;public File generatePDFReport() {
// Creating instance of HtmlReportMaker
HtmlReportMaker hrm = new HtmlReportMaker(dataSource);
// specify columns of data that must be summarized in table footer row
hrm.addSummaryColumn("Age", SummaryType.AVERAGE);
hrm.addSummaryColumn("Salary", SummaryType.SUM);
// summary section numbers decimal point setting
hrm.setSummaryDecimalPrecision(1);
// summary section numbers seperated by comma
hrm.setSummaryCommaSeperatedNumbers(true);
// show row's index
hrm.isRowIndexVisible(true);
//sql query to retrieve data rows
String sql = "select fullname as 'Name', age as 'Age', salary as 'Salary' from chamber limit 0,10";
// set the query retrieving data from database
hrm.setSqlQuery(sql);
String[] fonts = {"fonts/ArialBold.ttf", "fonts/MyOtherFont.ttf"}; // path to fonts that you want embed in pdf document
String baseUri = "the base uri";
return hrm.generatePDF("D:/mypdf.pdf",fonts,baseUri);
}
}
```#### Generate from list of objects ( for example : hibernate output )
```java
import io.github.birddevelper.salmos.XmlReportMaker;
import io.github.birddevelper.salmos.setting.SummaryType;
import io.github.birddevelper.salmos.setting.XmlReportElementType;
import lombok.Getter;
import lombok.Setter;
@Service
public class ReportService {@Getter
@Setter
public class Student {
private String name;
private int age;
private Date birthDate;
private List skills;
}
@AutoWired
StudentRepository studentRepository;public String generateHTMLReport() {
List studentList = studentRepository.findAll();
// Mapping the class fields to report columns (here we want only name and age, the reset of entity fields will be ignored)
Map fieldMap = new HashMap<>();
fieldMap.put("name", "Full Name");
fieldMap.put("age", "Age");
// buidling instance of ObjectFactory class
ObjectFactory objectFactory = new ObjectFactory();
// setting mapping fields
objectFactory.setReportFields(fieldMap);
// setting entity lists
objectFactory.loadObjects(studentList);
// building instance of HtmlReportMaker with ObjectFactory as input parameter
HtmlReportMaker htmlReportMaker = new HtmlReportMaker(objectFactory);
// generate report
return htmlReportMaker.generate();
}
}
```[Read More at Medium.com ](https://medium.com/javarevisited/with-salmos-report-in-spring-boot-generate-reports-in-few-lines-of-code-b5212486b921)
### Change Logs :
2.1.1 :
- Maven modelVersion changed to 4.0.0
- builder pattern2.1.0 :
- Embedded css style attribute for HTML report2.0.0 :
- Generate reports from list of objects (for example: list of entities retrieved by hibernate)1.2.0 :
- Export to PDF and TEXT files added.1.1.0 :
- GeneralReportMaker class added.
- Bugs fixed.1.0.0 :
- First release.
- Generate Reports from Sql Query
- Generate HTML and XML reports[Salmos report](https://m-shaeri.ir/blog/with-salmos-report-generate-reports-in-any-format-you-need/)