- The first is the use of thmeleaf
- th: attr set property value
- https://blog.csdn.net/sun_jy2011/article/details/40215423
- Some uses of th tag
- https://segmentfault.com/a/1190000009903821
-
Th: if th: text th: value th: selected, etc
<a href="register.html" title="" th:unless="${session.user} ne null" >Register</a> <a href="login.html" th:unless="${session.name} ne null" title="">Sign in</a> <a th:href="@{/logout}" th:if="${session.user}" title="">Log out</a> <span th:if="${session.user}"> <a th:href="@{/{id}/info(id=${session.user.id})}" >Info</a> </span>> <a th:href="@{/admin_login.html}" th:unless="${session.user} ne null" title="">Backstage</a> <a th:href="@{/admin_index.html}" th:if="${session.user} ne null" title="">Backstage</a> <a th:href="@{/login}" th:if="${session.user} " title="" th:text="'Welcome'+ ${session.name} + '!'">Log out</a>
- thymeleaf dropdown echo selected
<option value="Other" th:selected="${CloudDilatationDto.resource == 'Other'}">Other</option>
-
Loop iteration of thymelaf
<ul class="layui-nav layui-nav-tree" lay-filter="side-main" > <li class="layui-nav-item" th:each="menu: ${list}"> <a href="javascript:;" th:text="${menu.text}"> <i class="layui-icon"> < / I > Foundation</a> <dl class="layui-nav-child"> <dd th:each="record:${menu.childmenus}"> <!-- th:href="@{${record.href}}" --> <!-- <span th:text="${record.href}" class="change"></span> --> <a th:href="@{${record.href}}" > <i class="layui-icon" ></i> <span th:text="${record.ctext}"></span> </a> </dd> <!-- <dd><a href="javascript:;" href-url="login.jsp"><i class="layui-icon"> login page </dl> </li> </ul>
The installation of 3thymeleaf is very simple to import maven and configure in the application. Configuration file
spring.thymeleaf.mode=LEGACYHTML5 spring.thymeleaf.cache=false spring.thymeleaf.prefix=/WEB-INF/ spring.thymeleaf.suffix=.html
maven file
<! -- thymeleaf template engine, accessing static resources -- > <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <! -- this package was introduced to make spring.thymeleaf.mode=LEGACYHTML5 in application. Properties effective, This is to solve the problem that the template engine of thymeleaf is too strict in HTML verification -- > <dependency> <groupId>net.sourceforge.nekohtml</groupId> <artifactId>nekohtml</artifactId> </dependency>
4 Summary
Tymeleaf is a good template, which is similar to JSP freemaker but different from the template tag recommended by springboot.
Differences:
https://blog.csdn.net/qq_33314107/article/details/80834894