如何在 Thymeleaf 中拆分字符串 [英] How to split string in Thymeleaf
本文介绍了如何在 Thymeleaf 中拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有像 wange/25011.jpg|wange/25011-1.jpg
或 null 之类的图像名称,我想将它们拆分为 wange/25011.jpg
和 wange/25011-1.jpg
,如果为空则不拆分.我尝试了如下代码,但没有成功...
<td th:if="${brickset.imageNames} != null" th:each="image : ${#strings.arraySplit(brickset.imageNames, '|')}"><a href="#" th:href="${imageBaseUrl + image}"><img src="#" th:src="${imageBaseUrl + image}" height="64"/></a></td>
解决方案
这是我自己的答案:
<tr th:each="brickset : ${bricksets}" th:alt="${brickset.description}"><td><div th:unless="${brickset.imageNames == null}"><div th:each="image,status : ${#strings.arraySplit(brickset.imageNames, '|')}"><a href="#" th:href="${imageBaseUrl + image}" th:remove="${image} == null ? tag" th:title="${brickset.brand.name}"><img src="#" th:src="${imageBaseUrl + image}" height="64" th:remove="${status.index} > 0 ? tag"/></a></td></tr></tbody>
I have imageNames like wange/25011.jpg|wange/25011-1.jpg
or null, I want to split them to wange/25011.jpg
and wange/25011-1.jpg
, or no split if null. I tried code as below, but no work...
<td th:if="${brickset.imageNames} != null" th:each="image : ${#strings.arraySplit(brickset.imageNames, '|')}">
<a href="#" th:href="${imageBaseUrl + image}">
<img src="#" th:src="${imageBaseUrl + image}" height="64"/>
</a>
</td>
解决方案 Here is my own answer:
<tbody id="portfolio" class="clear fix">
<tr th:each="brickset : ${bricksets}" th:alt="${brickset.description}">
<td>
<div th:unless="${brickset.imageNames == null}">
<div th:each="image,status : ${#strings.arraySplit(brickset.imageNames, '|')}">
<a href="#" th:href="${imageBaseUrl + image}" th:remove="${image} == null ? tag" th:title="${brickset.brand.name}">
<img src="#" th:src="${imageBaseUrl + image}" height="64" th:remove="${status.index} > 0 ? tag"/>
</a>
</div>
</div>
</td>
</tr>
</tbody>
这篇关于如何在 Thymeleaf 中拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录
关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆