thymeleaf自定義屬性


例如我想給添加一個屬性data-page,可以根據(SpringEL/Ognl)表達式計算獲得。

需求:

期望效果

app個數大於0,有數據時鏈接

<xxx data-page="/app/list">

app個數等於0,沒有數據時鏈接如下

<xxx data-page="/app/create">

解決方法:

切換到Thymeleaf的數據屬性語法,使用data-屬性名稱和連字符-

摘錄自:thymeleaf 3.0.5中文參考手冊

<!DOCTYPE html>
<html>
<head>
<title>Good Thymes Virtual Grocery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" media="all" href="../../css/gtvg.css" data-th-href="@{/css/gtvg.css}" />
</head>
<body>
<p data-th-text="#{home.welcome}">Welcome to our grocery store!</p>
</body>

示例:

以下是筆者使用的代碼

<dd class="I124_dd_usual I124_dd_usual2 pageChange"data-th-data-page="${user.appCount>0?'/app/list':'/app/create'}">我的應用</dd>

實際生成代碼

 


免責聲明!

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



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