SpringBoot MVC RestAPIs – PostgreSQL – Download Excel File using Apache POI example

spring-mvc-restapi-download-excel-file-with-postgresql-apache-poi---feature-image

In the tutorial, we show you how to create a SpringBoot RestAPIs application that uses Spring JPA to get data from PostgreSQL records and uses Apache POI library to write data to a Excel file.

Related posts:
Java – How to read/write Excel file with Apache POI
How to use Spring JPA with PostgreSQL | Spring Boot
SpringBoot – Upload/Download MultipartFile to FileSystem – Bootstrap 4 + JQuery Ajax

Technologies

– Spring Boot – 2.0.6.RELEASE
– Spring JPA
– PostgreSQL
– Apache POI

Practice

Project Structure ->

spring-mvc-restapi-download-excel-file-with-postgresql-apache-poi---project-structure

Create SpringBoot project

Use SpringToolSuite to create a SpringBoot project with below dependencies:

Customer Model

Customer.java ->

JPA Customer Repository

CustomerRepository.java ->

Implement Excel Generator

ExcelGenerator.java ->

Implement RestAPI Controller

CustomerExcelDownloadRestAPI.java ->

Implement Download View

– Create ViewController.java ->

– Create .html view home.html ->

Initial Customers

– In main class, we use CommandLineRunner to init Customer’s records:

Database Configuration

application.properties ->

Run & Check Results

Run the SpringBoot project,

-> PostgreSQL’s records:

spring-mvc-restapi-download-excel-file-with-postgresql-apache-poi---select-all-customers

-> Excel Downloaded File:

spring-mvc-restapi-download-excel-file-with-postgresql-apache-poi---web-view

Network Logs:

spring-mvc-restapi-download-excel-file-with-postgresql-apache-poi---network-logs

-> File Content:

spring-mvc-restapi-download-excel-file-with-postgresql-apache-poi---excel-downloaded-file

SourceCode

SpringJpaExcelDownloader

By grokonez | January 10, 2019.



Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*