Thymeleaf is a modern server-side java template engine commonly used to build web applications. It is popular in Spring Boot projects for server side rendering of dynamic HTML pages. It has natural templating feature meaning HTML file can be directly opened in browser even without being processed by server. Below is a basic Thymeleaf program that showcases how Thymeleaf can be used with minimal configurations in Eclipse IDE.
Below is a practical example of showing list of product's categories in Thymeleaf:
<table class="table table-hover table-striped">
<thead class="table-dark">
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr th:each="category, iterationStatus : ${categories}">
<td th:text="${category.id}">1</td>
<td th:text="${category.name}">test@example.com</td>
<td>
<a class="btn btn-primary" th:href="@{/categories/{id}(id=${category.id})}" role="button">Show</a>
<a class="btn btn-info" th:href="@{/categories/update-screen/{id}(id=${category.id})}" role="button">Edit</a>
<form style="display: inline" th:action="@{/categories/delete/{id}(id=${category.id})}" th:method="delete">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
</tbody>
</table>
No comments:
Post a Comment