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>

实际生成代码

原文地址:https://www.cnblogs.com/passedbylove/p/11675269.html