Featured Article

Spring Boot MVC Thymeleaf Tutorial: Build Dynamic Web Apps Fast

Kenneth Jul 13, 2026

Spring Boot is a popular Java-based framework that simplifies the creation of enterprise-grade, production-ready applications. When combined with Model-View-Controller (MVC) architecture and Thymeleaf, a popular templating engine, it becomes a powerful trio for building web applications. This tutorial will guide you through the process of creating a Spring Boot MVC project with Thymeleaf templating.

how to paint yellow boots with tulips and rain boots
how to paint yellow boots with tulips and rain boots

Before we begin, ensure you have Java Development Kit (JDK) 8 or later, Apache Maven 3.x or later, and an Integrated Development Environment (IDE) like IntelliJ IDEA or Eclipse set up on your machine. Familiarity with MVC architecture and basic Spring Boot knowledge will also be helpful.

the instructions for how to use an app
the instructions for how to use an app

Setting Up a Spring Boot MVC Project

Spring Boot provides a starter kit for each type of application, including one for Spring Boot with Thymeleaf and MVC. Here's how to set it up using Spring Initializr.

the instructions for how to make an elf boots
the instructions for how to make an elf boots

1. Visit start.spring.io. Select 'Web' and add 'Thymeleaf' to depend on list. Click on 'GENERATE' to download the project as a ZIP file.

Project Structure

Easy Spring Kids Craft: Flower Boots Art
Easy Spring Kids Craft: Flower Boots Art

After unzipping, you'll find the following directories and files in your project:

src/main/java: Contains the main application's Java code.
src/main/resources: Holds static files like HTML templates and properties.
src/test/java: Contains test cases for the application.

Configuring Thymeleaf

Make This Spring Gnome with Rain Boots in Minutes!
Make This Spring Gnome with Rain Boots in Minutes!

Spring Boot automatically configures Thymeleaf when you add it as a dependency. However, you can further customize it by configuring the Spring Boot's application.properties file.

For example, to set the root directory for view resolution and the prefix and suffix for resolving views, add the following lines:

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

Arwens Riding Boots Elven Boots Sewing Pattern, Legolas Boots, Cosplay Boot Pattern, Diy Boots For Costume, Medieval Boot Covers Diy, How To Make Boots For Costume, How To Make Cosplay Boots, Making Boots For Costume, Cosplay Boots Tutorial
Arwens Riding Boots Elven Boots Sewing Pattern, Legolas Boots, Cosplay Boot Pattern, Diy Boots For Costume, Medieval Boot Covers Diy, How To Make Boots For Costume, How To Make Cosplay Boots, Making Boots For Costume, Cosplay Boots Tutorial

Creating MVC Components

Now let's create a simple MVC example using a Controller, Model, and View.

glue leaves to your shoes! Faerie Boots, Dark Fairy Core Shoes, Leaf Boots, Evil Fairy Shoes, Poison Ivy Boots, Green Fairy Shoes, Fairy Boot, Forest Fairy Shoes, Poison Ivy Shoes
glue leaves to your shoes! Faerie Boots, Dark Fairy Core Shoes, Leaf Boots, Evil Fairy Shoes, Poison Ivy Boots, Green Fairy Shoes, Fairy Boot, Forest Fairy Shoes, Poison Ivy Shoes
Miniature Leather Boots Collection, Ken Doll Shoes, Miniature Brown Boots, Miniature Leather Shoe Sewing, Brown Leather Doll Boots, Boots Diy, Military Ken Doll, Miniture Boots For Dolls, 16 Scale Boots
Miniature Leather Boots Collection, Ken Doll Shoes, Miniature Brown Boots, Miniature Leather Shoe Sewing, Brown Leather Doll Boots, Boots Diy, Military Ken Doll, Miniture Boots For Dolls, 16 Scale Boots
A Tale of Boots and Paint
A Tale of Boots and Paint
Custom Wide-Toe Boots
Custom Wide-Toe Boots
Boot Cover Tutorial & Modifications [archive 2010] | Crimebird Cosplay
Boot Cover Tutorial & Modifications [archive 2010] | Crimebird Cosplay
How to Make Gnome Boots TUTORIAL
How to Make Gnome Boots TUTORIAL
Doll Boot Making Tutorial
Doll Boot Making Tutorial
three different types of shoes are shown in black and white, with the names on them
three different types of shoes are shown in black and white, with the names on them
Combat Boot 3d Design
Combat Boot 3d Design

Controller: GreetingController.java

In the com.example.demo.controller package, create a GreetingController.java file with the following content:

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class GreetingController {

@GetMapping("/greeting")
public String greeting(Model model) {
model.addAttribute("message", "Hello, Thymeleaf with Spring Boot MVC!");
return "greeting";
}
}

View: greeting.html

Create a new directory named 'templates' under src/main/resources and add a new file named greeting.html with the following content:

{#extends 'layout.html' #}

Model: layout.html

Create another file named layout.html in the 'templates' directory to serve as the base template:

{#DOCTYPE html #}

Spring Boot MVC with Thymeleaf

...

That's it! Now, when you run the application and navigate to /greeting, you should see the greeting message displayed on the screen. This demonstrates the use of Spring Boot MVC with Thymeleaf templating.

With this foundation, you can now build more complex web applications, leveraging the power of Spring Boot, MVC architecture, and Thymeleaf templating. Happy coding!