In this tutorial I am going to extend previous project and show you how to handle with Forms in Spring Boot and Thymeleaf. I am going to create simple form for post. If post is valid, it will be displayed on the result view.
1. Set up the project as is described in previous post or checkout the source code.
2. pom.xml file is the same like in the previous project. I have only changed name and description.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jvmhub</groupId>
<artifactId>spring-boot-thymeleaf-form</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>spring-boot-thymeleaf-form</name>
<description>Spring Boot with Thymeleaf, part 2 - Forms</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Read more