Thymeleaxxuex学习bi笔记(四)

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>

inline

  • [[…]] 用在th:text
  • [(..)] 用在th:utext

示例如下:
msg = ‘This is great!‘, given this fragment:

<p>The message is "[(${msg})]"</p>
<p>The message is "[[${msg}]]"</p>

输出分别为:

<p>The message is "This is <b>great!</b>"</p>  <!-- <b> is unescaped -->
<p>The message is "This is &lt;b&gt;great!&lt;/b&gt;"</p>

Javascript也可以直接在inline中使用,用以替换其中的各类值。
示例如下:

<script th:inline="javascript">
    ...
    var username = [[${session.user.name}]];
    var username2 = "Sebastian \"Fruity\" Applejuice";
    var username3 = /*[[${session.user.name}]]*/ "Gertrud Kiwifruit";
    ...
</script>

结果输出为:

var username = "Sebastian \"Fruity\" Applejuice";
var username2 = Sebastian "Fruity" Applejuice;
var username3 = "Sebastian \"Fruity\" Applejuice"; /* 不破坏在html中进行显示 */

css的inline属性信息:
示例如下:
classname = ‘main elems’
align = ‘center’

  <style th:inline="css">
     .[[${classname}]] {
      text-align: [[${align}]];
    }
  </style>

输出如下:

<style th:inline="css">
    .main\ elems {
      text-align: center;
    }
</style>

猜你喜欢

转载自blog.csdn.net/blueheart20/article/details/80998177
今日推荐