Swiftorial Logo
Home
Swift Lessons
Tutorials
Learn More
Career
Resources

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:

  1. Include spring-boot-starter-thymeleaf dependency.
  2. Create HTML templates in src/main/resources/templates.
  3. 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.