Spring Boot FAQ: Top Questions
24. What is Thymeleaf and how is it used in Spring Boot?
Thymeleaf is a modern server-side Java template engine for web applications. Spring Boot offers native integration for rendering HTML views.
πΊοΈ Setup:
- Include
spring-boot-starter-thymeleaf
dependency. - Create HTML templates in
src/main/resources/templates
. - Return view name from controller method.
π₯ Example:
@GetMapping("/greet")
public String greet(Model model) {
model.addAttribute("name", "John");
return "greet";
}
π Expected Output:
Renders greet.html with the name John.
π οΈ Use Cases:
- Rendering dynamic HTML on the server.
- Building MVC web applications.