thymeleaf 一些写法

字符串拼接的顺序

当拼接字符串的时候要写在里面 由thymeleaf 维护会比较好

<p th:text="'商务网址:' + ${enterprise.businessUrl != null ? enterprise.businessUrl : ''}"> </p>

或者这样写由SpringEL引擎负责

<p th:text="${enterprise.contactsMobile!=null}?'联系方式:'+${enterprise.contactsMobile}:'联系方式:'">联系方式: </p>

这两种写法都比较稳!

这样的话 如果为空的话就只会显示 商务网址:

其他的写法的话就会出现 前面的字符不显示的情况。

 

图片url引用

<img src="images/mr1_img.jpg" th:src="@{${enterprise.enterprisePicture}}" />

 

<a>标签URL引用

<a th:href="${enterprise.creditUrl != null ? enterprise.creditUrl : ''}">

或者类似图片URl 的引用方式

<a th:href="@{http://{url}(url=${enterprise.businessUrl})}">

 

给某个文字加上链接(<a>)

把<a>标签写在thymeleaf 里

<h2 th:utext="${enterprise.enterpriseName != null 
                 ? '&lt;a href=' + enterprise.creditUrl + '&gt;' 
                 + enterprise.enterpriseName + '&lt;/a&gt;' : ''}">

或者 自己写在html

<a th:href="${enterprise.creditUrl != null ? enterprise.creditUrl : ''}">
    <h2 th:text="${enterprise.enterpriseName}">珠海汇丰征信有限公司</h2>
</a>

 

2018-2-2新增

方法中加入字符参数(url)

<button class="bu3" 
th:onclick="'locateTo(&quot;/myref/list?id=' + ${targetId} + '&quot;)'">我的关联</button>

&quot; -> "

方法传递多个变量参数

th:onclick="'addRef('+${targetId}+','+${wantRef.id} +')'"

 

内嵌页面(把公共页面提取出来,通过引入加入)

1、新建一个页面 , 加入锚点 th:fragment

100001_C6zy_2885163.png

2、在需要的位置通过 th:include 引入

100114_h5j1_2885163.png

转载于:https://my.oschina.net/zjllovecode/blog/1590181

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值