码迷,mamicode.com
首页 > 其他好文 > 详细

thymeleaf中的内联[ [ ] ]

时间:2014-10-17 16:51:25      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   使用   java   strong   sp   

一.文本内联

[[…]]之间的表达式在Thymeleaf被认为是内联表达式,在其中您可以使用任何类型的表达式,也会有效th:text属性。

<p>Hello, [[${session.user.name}]]!</p>

等同于:

<p>Hello, <span th:text="${session.user.name}">Sebastian</span>!</p>

为了让内联工作,我们必须激活它使用th:inline 属性,它有三个可能的值或模式(textjavascript 和 none)。让我们试着文本:

<p th:inline="text">Hello, [[${session.user.name}]]!</p>

如果不使用th:inline="text",则会被当做字符串显示。th:inline="javascript"表示能在js中使用[ [] ]取值。

 

标签的th:inline不需要包含内联的一个表达式,任何父标签都行,例如如下也是可以的:

 

<body th:inline="text">

   ...

   <p>Hello, [[${session.user.name}]]!</p>

   ...

</body>

二.脚本内联

  Thymeleaf提供一系列的“脚本”的内联模式功能,这样你就可以将你的数据在脚本中创建一些脚本语言。

  我们可以做的第一件事,写脚本内联表达式的值到我们的脚本。

<script th:inline="javascript">
    var user = [[${user.username}]];
      alert(user);
</script>
<script th:inline="javascript">
      var msg  = ‘Hello, ‘ + [[${user.username}]];
      alert(msg);
</script>

  只要加入th:inline="javascript"在js代码中才能使用[ [] ]

 

thymeleaf中的内联[ [ ] ]

标签:style   blog   color   io   ar   使用   java   strong   sp   

原文地址:http://www.cnblogs.com/suncj/p/4031486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!