Kotlin Spring Boot RestAPIs – Download Excel File – Apache POI + MySQL

kotlin-spring-boot-restapi-download-excel-file-spring-jpa-mysql-feature-image

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

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

Technologies

– Kotlin Spring Boot – 2.0.6.RELEASE
– Spring JPA
– MySQL
– Apache POI

Practice

Project Structure ->

kotlin-spring-boot-restapi-download-excel-file-spring-jpa-mysql-project-structure

Create Kotlin SpringBoot project

Use SpringToolSuite to create a Kotlin SpringBoot project with below dependencies:

Customer Model

Customer.kt ->

JPA Customer Repository

CustomerRepository.kt ->

Implement Excel Generator

ExcelGenerator.kt ->

Implement RestAPI Controller

CustomerRestAPIs.kt ->

Implement Download View

– Create ViewController.kt ->

– 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,

-> MySQL’s records:

kotlin-spring-boot-restapi-download-excel-file-spring-jpa-mysql-mysql-records-schema

-> Excel Downloaded File:

kotlin-spring-boot-restapi-download-excel-file-spring-jpa-mysql-download-view

kotlin-spring-boot-restapi-download-excel-file-spring-jpa-mysql-apache.poi-xlsx-file-results

SourceCode

KotlinSpringJpaExcelDownload

By grokonez | October 25, 2018.



Related Posts


Got Something To Say:

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

*