Kotlin Spring Boot RestAPIs – Download CSV File example – Apache Commons CSV + MySQL
Tags: kotlin, springboot, csv, apachecommons
Published: 2021-04-17 12:24:53

https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/kotlin-spring-boot-restapis-download-csv-file-example-apache-commons-csv-mysql

Kotlin Spring Boot RestAPIs – Download CSV File example – Apache Commons CSV + MySQL

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

Related posts:
- <a href="https://grokonez.com/kotlin/kotlin-read-write-csv-file-apache-commons-csv-example">Kotlin – How to read/write CSV file with Apache Commons CSV</a>
- <a href="https://grokonez.com/kotlin/kotlin-spring-jpa-postgresql-spring-boot-example">Kotlin Spring JPA + Postgresql | Spring Boot Example</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/kotlin-springboot-upload-download-file-multipartfile-thymeleaf-bootstrap-4">Kotlin SpringBoot Upload/Download File – MultipartFile + Thymeleaf + Bootstrap 4 example</a>

<!--more-->
<h2>Technologies</h2>
– Kotlin Spring Boot – 2.0.6.RELEASE
– Spring JPA
– MySQL
– Apache Commons CSV
<h2>Practice</h2>
Project Structure ->

<img src="https://grokonez.com/wp-content/uploads/2018/10/kotlin-springboot-restapi-download-csv-file-spring-jpa-mysql-project-structure.png" alt="kotlin-springboot-restapi-download-csv-file-spring-jpa-mysql-project-structure" width="289" height="312" class="alignnone size-full wp-image-15365" />
<h3>Create Kotlin SpringBoot project</h3>
Use SpringToolSuite to create a Kotlin SpringBoot project with below dependencies:

<pre><code class="language-html">&lt;dependency&gt;
	&lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
	&lt;artifactId&gt;kotlin-stdlib-jdk8&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
	&lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
	&lt;artifactId&gt;kotlin-reflect&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;      
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
&lt;/dependency&gt;   
&lt;dependency&gt;
	&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
	&lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
	&lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
	&lt;artifactId&gt;commons-csv&lt;/artifactId&gt;
	&lt;version&gt;1.5&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;mysql&lt;/groupId&gt;
    &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
    &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
    &lt;version&gt;2.3.0&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
<h3>Customer Model</h3>
- <code>Customer.kt</code> ->

More at:

https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/kotlin-spring-boot-restapis-download-csv-file-example-apache-commons-csv-mysql

Kotlin Spring Boot RestAPIs – Download CSV File example – Apache Commons CSV + MySQL