thymeleaf中的onclick


筆者在springboot中使用thymeleaf,springboot版本2.0.2.Release,maven中thymeleaf引用申明

<dependency>
   <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

此時並不能看到thymeleaf版本,大家可以使用mvn打個包,看看程序集里面的thymeleaf的版本,命令如下

mvn package -Dmaven.test.skip=true

打過包,打開項目的target目錄對應的jar文件,可看到thymeleaf版本是3.0.9

 

 

 

以下上網上轉載來的:

THYMELEAF 3.0.10更改日志
*改進了HTML事件處理程序屬性(th:on ),以允許將其值作為內聯JavaScript的片段(使用JAVASCRIPT模板模式)進行處理。

以前寫法(請放棄):
方式一:
<button class="btn" th:onclick="'getName(\'' + ${person.name} + '\');'">獲得名字</button>
方式二:
<button class="btn" th:onclick="'getName(' + ${person.name} + ');'">獲得名字</button>
方式三:
<button th:onclick="|getName(${person.name} )|">獲得名字</button>

現在的寫法:
<button class="btn" th:onclick="getName([[${person.name}]]);">獲得名字</button> 3.0.10版本
更新公告:http://forum.thymeleaf.org/Thymeleaf-3-0-10-JUST-PUBLISHED-td4031348.html

 

由於筆者本地是3.0.9,所以使用了以下代碼

<button th:onclick="|getName(${person.name} )|">獲得名字</button>

講真,筆者不喜歡thymeleaf,語法不方便記憶,過一段時間就忘記了。性能也不怎么高,緩存搞死人。如果有選擇,我會選擇高性能的,httl等,他們能根據模板生成java類,性能高。目前還沒去試用。

轉載自:https://blog.csdn.net/u010592926/article/details/86373871


免責聲明!

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



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