SpringBoot Upload Multiple Files to MySQL Example – Thymeleaf + Spring JPA Audit

springboot-restapi-uplacoad-multiple-files-to-mysql-spring-jpa-audit-date-feature-image

In the tutorial, we show you how to build a SpringBoot RestAPIs to upload multiple files to MySQL database with Thymeleaf frontend, and Spring JPA Audit feature.

Related posts:
Spring Data JPA Auditing Example – SpringBoot RestAPIs + MySQL
SpringBoot RestAPIs + Thymeleaf – Upload/Download Multiple Files to FileSystem Example

Technologies

– Java 8
– Maven 3.6.1
– SpringBoot
– Thymeleaf
– Bootstrap 4

Goal

– We create a SpringBoot project as below:

springboot-restapi-upload-multiple-files-to-mysql-spring-jpa-audit-date-project-structures

– Upload Multiple Files ->

springboot-restapi-upload-multiple-files-to-mysql-spring-jpa-audit-date-upload-successfully

springboot-restapi-upload-multiple-files-to-mysql-spring-jpa-audit-date-updated-records

– Download Form ->

springboot-restapi-upload-multiple-files-to-mysql-spring-jpa-audit-date-download-files

Practice

SpringBoot Backend Implementation
Create SpringBoot project

We use SpringToolSuite to create a SpringBoot project with below dependencies:

jackson-datatype-jsr310 is used to support Java 8 Date/Time for JPA Audit feature.

Implement DateAudit

– Configure JPA Auditing:

– Implement DateAudit ->

@EntityListeners annotation is used to specify callback listener classes. We use the JPA entity listener class of Spring Data AuditingEntityListener.
@MappedSuperClass annotation is used to move the properties to a base class DateAudit which would be extended by all your audited entities.

Build File Model

FileModel.java ->

Define File Repository

FileRepository.java ->

Upload Multiple Files Controller

UploadFileController.java ->

– We can limit the size of uploaded file by using below configuration in application.properties ->

Download Files Controller

– Firstly, create FileInfo.java ->

– Implement download controller DownloadFileController.java ->

Application Configuration

application.properties ->

Main Class Implementation

– Set the default timezone for our application to UTC.

Thymeleaf Frontend Implementation
Upload Form

uploadform.html ->

Download Form

listfiles.html ->

Run & Check Results

Run the SpringBoot project,

– Upload Multiples files:

springboot-restapi-upload-multiple-files-to-mysql-spring-jpa-audit-date-uploaded-files

springboot-restapi-upload-multiple-files-to-mysql-spring-jpa-audit-date-form-upload-files

-> Results:

springboot-restapi-upload-multiple-files-to-mysql-spring-jpa-audit-date-upload-successfully

springboot-restapi-upload-multiple-files-to-mysql-spring-jpa-audit-date-records-in-file_models_tables

– Change text in grokonez-about-us.txt then upload 3 files again, results ->

springboot-restapi-upload-multiple-files-to-mysql-spring-jpa-audit-date-updated-records

– Download files:

springboot-restapi-upload-multiple-files-to-mysql-spring-jpa-audit-date-download-files

-> results:

springboot-restapi-upload-multiple-files-to-mysql-spring-jpa-audit-date-check-downloaded-files-images

SourceCode

SpringBootUploadMultiFileToMySQL

By grokonez | November 7, 2018.



Related Posts


Got Something To Say:

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

*