(九)Thymeleaf用法——Themeleaf注釋


4. 注釋   

模板名稱:comment.html

4.1 標准 HTML/XML注釋 

     語法:<!--     -->     

4.2 解析器級注釋塊(Parser-level comment blocks)    

語法:<!--/*    */-->     
thymeleaf解析時會移除代碼    
<!--/*--> 
  <div>
     you can see me only before Thymeleaf processes me!
  </div>
<!--*/-->
單行:<!--/*  xxxxx  */-->    
雙行:          
<!--/*-->          
     Xxxxxx          
     Xxxxxx         
<!--*/-->

4.3 針對原型的注釋

語法:<!--/*/    /*/-->
<span>hello!</span>
<!--/*/
  <div th:text="${...}">
    ...
  </div>
/*/-->
<span>goodbye!</span>
thymealeaf解析時會移除掉此標簽對,但不會移除其中的內容。
解析完成:
<span>hello!</span>
 
  <div th:text="${...}">
    ...
  </div>
 
<span>goodbye!</span>

4.4 與th:block結合

thymealeaf解析時會移除掉此標簽對,但不會移除其中的內容。
th:block 是一個屬性容器,允許模板開發人員指定他們想要的任何屬性。Thymeleaf將執行這些屬性,然后簡單地制作塊,而不是其內容消失。
<table>
  <th:block th:each="user : ${users}">
    <tr>
        <td th:text="${user.login}">...</td>
        <td th:text="${user.name}">...</td>
    </tr>
    <tr>
        <td colspan="2" th:text="${user.address}">...</td>
    </tr>
  </th:block>
</table>
<table>
    <!--/*/ <th:block th:each="user : ${users}"> /*/-->
    <tr>
        <td th:text="${user.login}">...</td>
        <td th:text="${user.name}">...</td>
    </tr>
    <tr>
        <td colspan="2" th:text="${user.address}">...</td>
    </tr>
    <!--/*/ </th:block> /*/-->
</table>

 

view this:
  <div>  
        <ol>  
        <li>解釋器級注釋塊(thymeleaf解析時會移除掉注釋塊所有代碼):  
        <!--/* this is content! */-->  
        </li>  
        <li>針對原型的注釋(thymeleaf解析時會移除掉注釋標簽,但保留標簽內的內容):  
            <!--/*/ this is content! /*/-->  
        </li>  
        <li>與th:block結合(thymeleaf解析時會移除掉th:block注釋塊,但保留標簽內的內容):  
            <!--/*/<th:block th:each="user:${list}">/*/-->  
            <div th:text="${user.userName}"></div>  
            <!--/*/</th:block>/*/-->  
        </li>  
        </ol>  
    </div>  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM