Thymeleaf is a server-side Java template engine that can be integrated with Spring Boot. It allows for the creation of dynamic web pages with HTML, CSS, and JavaScript.
HTML
Thymeleaf with Spring Boot
Thymeleaf is a server-side Java template engine that can be integrated with Spring Boot. It allows for the creation of dynamic web pages with HTML, CSS, and JavaScript. I will cover the following concepts in Thymeleaf: Iteration, Conditional Statements, Fragments, Inheriting Thymeleaf Template, and how to add custom and bootstrap JS and CSS files.
Prerequisites
To follow this tutorial, you will need:
Java 8 or later installed
Spring Boot 2.1.0 or later
A basic understanding of HTML, CSS, and JavaScript
Setting up a Spring Boot project with Thymeleaf
Add the Thymeleaf dependency to your project's pom.xml file:
<h1 th:if="${gender}=='M'">User is Male</h1>
<h1 th:unless="${gender}=='M'">User is Female</h1>
Switch
<div th:switch="${#lists.size(lon)}">
<h1 th:case="'0'">List is empty</h1>
<h1 th:case="'1'">List contains one element</h1>
<h1 th:case="*">List contains more than one elements</h1>
</div>
Inheriting Thymeleaf Templates
Thymeleaf allows you to define templates that can be inherited by other templates. You can use the th:replace attribute to inherit a template.
To add custom CSS and JS files to your Thymeleaf templates, you can use the th:href attribute. This attribute allows you to specify the location of the file.