This tutorial will walk you through the steps of creating a Form Data Binding and Validation Example with Spring Boot and FreeMarker

What you'll build

What you'll need

  • JDK 1.7+
  • Maven 3+

Stack

  • Java
  • Spring Boot
  • FreeMarker
  • HTML, CSS

Init project structure and dependencies

Project structure

├── src
│   └── main
│       ├── java
│       │   └── com
│       │       └── hellokoding
│       │           └── springboot
│       │               ├── FormController.java
│       │               ├── User.java
│       │               └── WebApplication.java
│       └── resources
│           ├── static
│           │   ├── css
│           │   │   └── main.css
│           │   └── js
│           │       └── main.js
│           ├── templates
│           │   └── form.ftl
│           └── application.properties
└── pom.xml

Project dependencies


Define DTO, Controller and View Template

Data transfer object (DTO)


Controller


View template


Config and Run

Application Configuration



Run the application

Type the following Maven command on your terminal console at the project root directory

mvn clean spring-boot:run

Source code

https://github.com/hellokoding/hellokoding-courses/tree/master/springboot-examples/springboot-freemarker-form-validation