Thymeleaf Java View Technology
Sankar Karra
Senior Engineer L2 at Ness Digital Engineering Private Limited | Expert in Java, Spring Boot, Spring Reactive, & Microservices | Cloud (AWS, Azure) | CI/CD (GitHub Actions, Jenkins) | MySQL, MongoDB | Docker & Kubernetes
This article tells about ThymeLeaf all tags
Library or namespace or import
2. <a th:href="@{/sp/save}">Update</a>
@{} here enter path or url
<a th:href="@{/}"></a> link
Example:
Java code:
@RequestMapping("/spec")//class level
@GetMapping("/delete")//method level
@RequestParam Integer id//Reading form data
UI code:
<a th:href="@{/spec/delete(id=${ob.id})}">Update</a>
3. @{}
url path
4. th:each
for each loop
<tr th:each="objectRef:${variableName}">
??????<td th:text="${objectRef.variableName}"></td>
??????<tr>
5. th:text
Display text in the browser
<div th:text="${attributeName}"></div>
6. ${}
To read variable data or to set variable data or EL used to display data at browser.
7. <form th:action=""></form>
method path or after submition goint to that url
example:
@PostMapping("/save")
<form th:action="@{/spec/save}"></form>
8. th:object
To read object data.
领英推荐
Link form with Object.
Example:
th:object="${}"
@ModelAttribute Employee objectRef
<form th:object="${ObjectRef}></form>
9. th:field
In thymeleaf * means linking
In form name="empName" id="empName"
th:field="*{variableName}"
*{variableName} it will call getter and setter methods.
Bi-Directional means Reading field data and Setting field or variable data
Replace name=" " id=" " with th:field
10. THML form:
<form action="" method="GET/POST"></form>
Uni-directional and static
11. ThymeLeaf form
Form connected to Object
<form th:action="@{/}" method="GET/POST" th:object="${objectRef}" ></form>
12. th:if
if condition
Example
if(10>12)
return true;
else return false;
th:if="${variablename!=null}
13. th:src
use th:src to localte static files like .js, .ts etc.
th:src="@{js/script.js}
img th:src for File Field data to Display
Example: <imag th:src="${}"/>
----------------------THE END------------------