全国免费服务热线:

18982081108
✕

成都弹性云服务器,成都高防云服务器,互联网数据服务,成都祈钰瑶

springboot项目小结thymeleaflayui使用小结-创新互联

  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 等等

    成都创新互联主营扶沟网站建设的网络公司,主营网站建设方案,成都app软件开发公司,扶沟h5小程序制作搭建,扶沟网站营销推广欢迎扶沟等地区企业咨询
    <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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。