Spring Boot upload multiple files example with freemarker

Spring Boot upload multiple files example with freemaker walks you through the process of creating a upload multiple files example step by step. Here, we are using freemaker template in frontend side. Noticed that Spring Boot is sub-project developed by developers of spring framework, Spring Boot makes it easy to create stand-alone, production-grade Spring based applications with minimum configuration possible.

Other interesting posts you may like

Let’s begin:

If you are beginner on Spring Boot and Freemaker, before starting you should refer to the tutorial Spring Boot FreeMarker Hello World Example

Project structure
We will create a project with directory structure like below

Spring boot upload multiple files example with Freemaker

Maven Dependencies
To create Spring boot upload multiple files example with freemaker, you need to add dependencies into pom.xml file like below:

Create the Controller
We create a upload controller named UploadController like below.

Create the View

We create a upload form using freemaker template and display uploaded files.

Configuration properties
We are setting these below properties in application.properties for FreeMarker templates file, stored src/main/resources directory like below:

Configure Spring Web Application
To set our application up as a servlet application we extend our main class with SpringBootServletInitializer and override the configure method using SpringApplicationBuilder.

Dig deeper: This line code

help to makes a directory for uploading files if not exists

Run Application
To deploy and run our Spring boot upload multiple files example with freemaker on web container, we run the below command in console

After running successfully, you can access the application via URL http://localhost:8080 and see the homepage such as

Spring boot upload multiple files example with Freemaker

Now, you can choose which files you want to upload by hitting button “Choose files”, then the screen should show like this

Spring boot upload multiple files example with Freemaker

To click the button “Upload files” to upload your files, the screen should be like this

Spring boot upload multiple files example with Freemaker

That’s it on the tutorial Spring boot upload multiple files example with Freemaker.

References
Spring Boot FreeMarker

Download complete source code, please click link below

spring-boot-upload-multiple-files.zip (48 downloads)

Github: https://github.com/javabycode/spring-boot-upload-multiple-files

Leave a Comment

*

Please share it if you found this useful
Hide Buttons