Featured Article

Spring Boot Thymeleaf Example Tutorial Guide

Kenneth Jul 13, 2026

Spring Boot, a popular Java-based framework, simplifies the process of creating stand-alone, production-grade Java applications. When it comes to rendering views in Spring Boot, Thymeleaf is a popular templating engine. It's capable of creating clean and semantic HTML5 templates. Let's explore an example of using Thymeleaf in a Spring Boot application.

Green Floral Frye Boots, Sage Cowboy Boots, Floral Cowboy Boots, Green Cowboy Boots With Floral Design, Floral Green Boots Design, Sage Green Cowboy Boots, Boot Barn Floral Boots, Sage Green Cowgirl Boots, Traditional Embroidered Boots For Spring
Green Floral Frye Boots, Sage Cowboy Boots, Floral Cowboy Boots, Green Cowboy Boots With Floral Design, Floral Green Boots Design, Sage Green Cowboy Boots, Boot Barn Floral Boots, Sage Green Cowgirl Boots, Traditional Embroidered Boots For Spring

Before we dive into the example, ensure you have a running Spring Boot project. If you haven't, you can create one using start.spring.io, including 'Web' and 'Thymeleaf' as dependencies.

Hoodoo Shoe Magic, Spell To Make Plants Grow, Pagan Home Protection, House Protection Spell Front Doors, Front Door Protection Spell, Front Door Witchcraft, Wormwood For Protection, Moss In Witchcraft, Shoe Spells
Hoodoo Shoe Magic, Spell To Make Plants Grow, Pagan Home Protection, House Protection Spell Front Doors, Front Door Protection Spell, Front Door Witchcraft, Wormwood For Protection, Moss In Witchcraft, Shoe Spells

Setting Up Thymeleaf ViewResolver

Once you have your project set up, configure Thymeleaf as your default view resolver. In your application.properties file, add the following lines:

an anime character is standing in front of a drawing
an anime character is standing in front of a drawing

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

Creating a Simple Thymeleaf Template

small white flowers are growing in the grass
small white flowers are growing in the grass

Create a new file named index.html in the src/main/resources/templates/ directory. Add the following code:

```html Spring Boot Thymeleaf Example

Welcome to Spring Boot Thymeleaf Example!

This is a fallback message.

Repurposing Vintage Embroidered Pillowcases
Repurposing Vintage Embroidered Pillowcases

```

Populating Data from Controller

Now, let's send some data from our Spring Boot controller to populate this template. Create a new controller class named IndexController:

```java @Controller public class IndexController { @GetMapping("/") public String index(Model model) { model.addAttribute("greeting", "Hello, Thymeleaf!"); return "index"; } } ```

The index method adds a new attribute named greeting with the value "Hello, Thymeleaf!". The return statement corresponds to the template name.

a hand holding a bouquet of daisies against a blue sky
a hand holding a bouquet of daisies against a blue sky

Displaying List Data with Thymeleaf

Let's display a list of items in an unordered list using Thymeleaf. Add the following code to your index.html file:

a pair of boots sitting on top of each other
a pair of boots sitting on top of each other
Thymus Bressingham Thyme | Ground Cover Plants | STEPABLES
Thymus Bressingham Thyme | Ground Cover Plants | STEPABLES
How to Grow Thyme: The Complete Beginner’s Herb Guide
How to Grow Thyme: The Complete Beginner’s Herb Guide
a pair of black boots with plants growing out of them
a pair of black boots with plants growing out of them
two pink rain boots with flowers in them sitting on the ground next to a brick wall
two pink rain boots with flowers in them sitting on the ground next to a brick wall
Thyme for Clear & Glowing Skin 🌿 | Natural Skin Care Tips & Herbal Acne Remedy
Thyme for Clear & Glowing Skin 🌿 | Natural Skin Care Tips & Herbal Acne Remedy
an image of some stickers that are on the back of a cell phone screen
an image of some stickers that are on the back of a cell phone screen
Green Rain Boots Aesthetic, Welly Boots Aesthetic, Vintage Hunter Boots, Wellies Aesthetic, Old Hunter Boots, English Wellies, Dark Green Hunter Boots, English Countryside Boots, Vintage Hunter Wellies
Green Rain Boots Aesthetic, Welly Boots Aesthetic, Vintage Hunter Boots, Wellies Aesthetic, Old Hunter Boots, English Wellies, Dark Green Hunter Boots, English Countryside Boots, Vintage Hunter Wellies
clover triflium sprouts with white flowers and green leaves are shown in this brochure
clover triflium sprouts with white flowers and green leaves are shown in this brochure

```html

```

Next, update your IndexController to pass a list of items to the view:

```java @GetMapping("/") public String index(Model model) { model.addAttribute("greeting", "Hello, Thymeleaf!"); model.addAttribute("items", Arrays.asList("Item 1", "Item 2", "Item 3")); return "index"; } ```

Navigating to the Template

Finally, to navigate to our Thymeleaf template, run your Spring Boot application and visit localhost:8080. You should see a welcoming message and a list of items displayed on the page.

That's it! You've successfully created a Spring Boot application with Thymeleaf templating. Dive deeper into Thymeleaf's features to create more dynamic and engaging web pages. Happy coding!