- Spring 5.0 Projects
- Nilang Patel
- 129字
- 2021-07-02 12:34:59
Defining the view templates
We will be using the Thymeleaf template engine for handling server-side templates. Thymeleaf provides various dialects and conditional blocks for rendering the dynamic content within the static HTML. Let's look at some simple syntactical element of Thymeleaf, as follows:
<!-- Dynamic content in HTML tag -->
<div class="alert alert-info">[[${country.name}]]</div>
<!-- Dynamic attributes -->
<span th:class="|alert ${error ? 'alert-danger': _}|">[[${errorMsg}]]</span>
<!-- Looping -->
<ol>
<li th:each="c : ${countries}">
[[${c.name}]]
</li>
</ol>
<!-- Conditionals -->
<div class="alert alert-warning" th:if="${count == 0}">No results found</div>
<!-- Custom attributes -->
<div th:attr="data-count=${count}"></div>
<!-- Form element value -->
<input type="text" th:value="${country.name}" name="name" />
From the previous examples, we can observe that the items to be evaluated by Thymeleaf are prefixed with th: and any content to be rendered between the tags can be done either using th:text or [[${variable}]]. The latter syntax has been introduced in Thymeleaf 3. This was a very short primer, as going in to depth on Thymeleaf is out of the scope of this book. A beautiful guide explaining different parts of the template can be found at http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html.
- Cisco OSPF命令與配置手冊
- 物聯(lián)網(wǎng)智慧安監(jiān)技術(shù)
- 高校網(wǎng)絡(luò)道德教育研究
- EDA技術(shù)與VHDL編程
- Oracle SOA Suite 11g Performance Tuning Cookbook
- Force.com Development Blueprints
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- 計算機網(wǎng)絡(luò)與數(shù)據(jù)通信
- 射頻通信系統(tǒng)
- 物聯(lián)網(wǎng)通信技術(shù)
- 新手易學(xué):新手學(xué)淘寶開店
- INSTANT KineticJS Starter
- 轉(zhuǎn)化:提升網(wǎng)站流量和轉(zhuǎn)化率的技巧
- 無線傳感器網(wǎng)絡(luò)定位技術(shù)
- NB-IoT原理和優(yōu)化