温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

springboot 项目小结thymeleaf layui 使用小结

发布时间:2020-07-23 17:11:25 来源:网络 阅读:2427 作者:老萧23 栏目:开发技术
  1. 第一是 thymeleaf 的使用

  • th:attr 设置属性值
  • https://blog.csdn.net/sun_jy2011/article/details/40215423
  • th 标签的一些使用
  • https://segmentfault.com/a/1190000009903821
  • th:if th:text th:value th:selected 等等

    <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="">后台</a>
    
                               <a th:href="@{/admin_index.html}" th:if="${session.user} ne null"  title="">后台</a>
                              <a th:href="@{/login}" th:if="${session.user} " title="" th:text="'欢迎'+ ${session.name} + '!'">Log out</a>
  • thymeleaf 下拉回显选中
    <option value="其他"   th:selected="${CloudDilatationDto.resource == '其他'}">其他</option>

  1. 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">&#xe620;</i>基础</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">&#xe621;</i>登录页</a></dd> -->
    
                    </dl>
                </li>
            </ul>

3thymeleaf 的 安装 很简单 导入maven 并且在 application.配置文件中进行配置

spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=/WEB-INF/
spring.thymeleaf.suffix=.html

maven文件

<!-- thymeleaf模板引擎,访问静态资源 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- 引入该包为了让application.properites中的 spring.thymeleaf.mode=LEGACYHTML5 生效,
是为了解决 thymeleaf模板引擎过于严格的HTML校验-->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>

4总结

thymeleaf 是很不错的模板 和jsp freeemaker 比较相似 但还是有不同 是springboot 推荐的模板标签。

不同之处:
https://blog.csdn.net/qq_33314107/article/details/80834894

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI