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.

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.

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.

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

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

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

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




![Boot Cover Tutorial & Modifications [archive 2010] | Crimebird Cosplay](https://i.pinimg.com/originals/ce/95/f9/ce95f91f3a0300b86fda0f4036bb4c28.jpg)




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 #}
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!