Featured Article

Spring Boot Thymeleaf Starter Tutorial: Build Web Apps Faster

Kenneth Jul 13, 2026

Spring Boot, the popular Java-based framework, has made it incredibly easy to develop microservices and web applications. The Spring Boot Starter Thymeleaf dependency simplification has further streamlined this process by integrating the Thunderleaf templating engine. Let's delve into a comprehensive tutorial on how to set up and use Spring Boot Starter Thymeleaf.

a pair of boots with moss growing on the inside and outside, sitting on top of a table
a pair of boots with moss growing on the inside and outside, sitting on top of a table

Before we dive in, ensure you have Java Development Kit (JDK) 8 or later, Apache Maven 3.2 or later, and a favorite text editor or IDE installed. We'll use Spring Tool Suite (STS) for this example, but any IDE can work just as well.

Gladiator Boot Tutorial
Gladiator Boot Tutorial

Setting Up Your Spring Boot Project with Thymeleaf

Our first step is to create a new Spring Boot project. In STS, go to File > New > Spring > Project, choose 'Spring Boot' and click next. Name your project, select 'Web' as the dependency package, and choose 'Thymeleaf' under 'Additional Libraries'.

Baby Bootie Pattern 4 (Terra Verde \
Baby Bootie Pattern 4 (Terra Verde \

Maven will automatically add the necessary starter dependencies to your 'pom.xml' file. Now, thymeleaf-spring-5 is included in your project.

Creating a Basic Controller and View

spring boot starter thymeleaf tutorial
spring boot starter thymeleaf tutorial

Next, let's create a simple controller and an accompanying view. In your package explorer, right-click on the 'controller' folder and create a new class named 'GreetingController'. Inside, add the following code:

```java @Controller public class GreetingController { @GetMapping("/greeting") public String greeting(Model model) { model.addAttribute("name", "Thymeleaf Tutorial"); return "greeting"; } } ```

The '@Controller' annotation indicates that this class handles HTTP requests. The '@GetMapping("/greeting")' method maps GET requests sent to "/greeting" to the 'greeting' method.

Creating a Basic Thymeleaf Template

an illustrated poster with flowers and herbs on it
an illustrated poster with flowers and herbs on it

Now, create a new folder named 'templates' under 'src/main/resources'. Inside, create another folder named 'thymeleaf'. Then, create a file named 'greeting.html' inside 'thymeleaf'. Add the following code to 'greeting.html':

```html Greeting Template

Welcome, Default Name!

This is a simple greeting page generated by Spring Boot with Thymeleaf.

How to Make a Mossy Boot Planter
How to Make a Mossy Boot Planter

```

The 'th:text="${name}"' statement is a Thymeleaf expression that replaces the 'Default Name' text with the name passed from the controller.

Building and Running Your Application

an old fashion sewing pattern from the 1950's for hats and boots with buttons
an old fashion sewing pattern from the 1950's for hats and boots with buttons
Doll Boot Tutorial
Doll Boot Tutorial
10-minute Boot Topper Tutorial - Betz White
10-minute Boot Topper Tutorial - Betz White
A Tale of Boots and Paint
A Tale of Boots and Paint
How To Alter Modern Day Boots For Larp
How To Alter Modern Day Boots For Larp
DIY Gardening Gnome Pattern with Sun Hat, Apron, and Extras
DIY Gardening Gnome Pattern with Sun Hat, Apron, and Extras
Pointed Shoe Pattern for SD Male (8.5cm Foot)
Pointed Shoe Pattern for SD Male (8.5cm Foot)
the instructions for how to sew an army uniform with pictures and text on it
the instructions for how to sew an army uniform with pictures and text on it
Simple Ways How To Grow Winter Thyme Indoors
Simple Ways How To Grow Winter Thyme Indoors

Next, build your application with the following command (in the terminal or command prompt):

``` mvn spring-boot:run ```

After your application starts, open a web browser and navigate to 'http://localhost:8080/greeting'. You should see your greeting template displaying the message "Welcome, Thymeleaf Tutorial!"

Creating a Layout and Including it in Your Templates

To add consistency across your website, you can create a layout that includes a common header and footer. In the 'thymeleaf' folder, create a new file named 'layout.html'. Add the following code:

```html Thymeleaf Tutorial

Welcome to a Spring Boot + Thymeleaf Tutorial!
Thanks for learning with us. Happy coding!
```

The 'layout:fragment' attribute points to a section of the template that will be replaced with the content of the included template. In your 'greeting.html' file, add 'layout:decorate="layout.html"' to use this layout:

```html Default Title

Welcome, Default Name!

This is a simple greeting page generated by Spring Boot with Thymeleaf.

```

Now, all your future templates can use 'layout:decorate' to use the same layout.

That's it! You've successfully set up and used Spring Boot Starter Thymeleaf to create a dynamic website. Now, you can create more complex templates and controllers to build full-featured web applications. Happy coding!