Download CSV File from SpringBoot RestAPI + MySQL – using Apache Commons CSV + Spring JPA


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 Apache Commons CSV library to write data to a CSV file.

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


– Spring Boot – 2.0.6.RELEASE
– Spring JPA
– Apache Commons CSV – 1.5


Project Structure ->


Create SpringBoot project

Use SpringToolSuite to create a SpringBoot project with below dependencies:

Customer Model ->

JPA Customer Repository ->

Implement CSV Writer ->

Implement RestAPI Controller

CustomerCSVDownloadRestAPI ->

Implement Download View

– Create ->

– Create .html view home.html ->

Initial Customers

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

Database Configuration ->

Run & Check Results

Run the SpringBoot project,

-> MySQL’s records:


-> CSV Downloaded File:





By grokonez | October 17, 2018.

Related Posts

1 thought on “Download CSV File from SpringBoot RestAPI + MySQL – using Apache Commons CSV + Spring JPA”

  1. Hello thanks for the tutorial, after following it and practice the data I got for the csv file is on a single column, thank you for helping me

Got Something To Say:

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