- 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.
- CorelDRAW X6 中文版圖形設計實戰從入門到精通
- 高校網絡道德教育研究
- Force.com Development Blueprints
- Oracle SOA Suite 11g Performance Tuning Cookbook
- 物聯網關鍵技術及應用
- 城市治理一網統管
- 網絡空間全球治理觀察
- 互聯網安全的40個智慧洞見(2016)
- 一本書讀懂TCP/IP
- Laravel Application Development Cookbook
- 移動互聯網環境下的核心網剖析及演進
- 想象的互動:網絡人際傳播中的印象形成
- Architecting Data:Intensive Applications
- 互聯網戰略變革與未來
- LiveCode Mobile Development Beginner's Guide