CSV File – Download from SpringBoot RestAPI + OpenCSV + MySQL

springboot-restapi-download-csv-file-springjpa-mysql-database-feature-image

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

Related posts:
Java – How to read/write CSV file with OpenCSV
How to use Spring JPA MySQL | Spring Boot
SpringBoot – Upload/Download MultipartFile to FileSystem – Bootstrap 4 + JQuery Ajax

Technologies

– Spring Boot – 2.0.6.RELEASE
– Spring JPA
– MySQL
– OpenCSV – 4.0

Practice

Project Structure ->

springboot-restapi-download-csv-file-springjpa-mysql-database-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 CSV Writer

WriteDataToCSV.java ->

Implement RestAPI Controller

CsvDownloadController.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,

-> MySQL’s records:

springboot-restapi-download-csv-file-springjpa-mysql-database-tables-records

-> CSV Downloaded File:

springboot-restapi-download-csv-file-springjpa-mysql-database-view

springboot-restapi-download-csv-file-springjpa-mysql-database-download-network-request

springboot-restapi-download-csv-file-springjpa-mysql-database-csv-file-content

SourceCode

SpringBootCsvDownloadAPI

By grokonez | October 21, 2018.



Related Posts


Got Something To Say:

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

*