SpringBoot MVC RestAPIs – MongoDB – Export/Download Excel File using Apache POI example

springboot-mvc-restapi-export-download-excel-file-mongodb-apache-poi---feature-image

In the tutorial, we show you how to create a SpringBoot RestAPIs application that uses Spring Data MongoDB to get data from MongoDB collection 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 SpringData MongoRepository to interact with MongoDB
SpringBoot – Upload/Download MultipartFile to FileSystem – Bootstrap 4 + JQuery Ajax

Technologies

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

Practice

Project Structure ->

springboot-mvc-restapi-export-download-excel-file-mongodb-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,

-> MongoDB’s documents:

springboot-mvc-restapi-export-download-excel-file-mongodb-apache-poi---find-all-mongodb-documents

-> Excel Downloaded File:

springboot-mvc-restapi-export-download-excel-file-mongodb-apache-poi---web-view

Network Logs:

springboot-mvc-restapi-export-download-excel-file-mongodb-apache-poi---network-logs

-> File Content:

springboot-mvc-restapi-export-download-excel-file-mongodb-apache-poi---download-files

SourceCode

SpringJpaExcelDownloader

By grokonez | January 12, 2019.



Related Posts


Got Something To Say:

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

*