我有像wange/25011.jpg|wange/25011-1.jpg
或null的imageNames,我想将它们拆分为wange/25011.jpg
和wange/25011-1.jpg
,或者如果为null则不拆分。我尝试了如下代码,但没有工作......
<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>
答案 0 :(得分:8)
这是我自己的答案:
<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>
答案 1 :(得分:0)
就我而言,我有一个像下面这样的字符串
String times = "Product1#100$@@@Product2#130$";
我想在原始表格中显示产品名称和价格,为此,我创建了这个。我用它来向用户发送订单确认电子邮件
<tr th:each="item, count : ${#strings.arraySplit(items, '@@@')}">
<td width="75%" align="left"
style="font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 24px; padding: 15px 10px 5px 10px;"
th:text="${#strings.arraySplit(item,'#')[0] + ' ('+ (count.index + 1) +')'}">
</td>
<td width="25%" align="left"
style="font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 24px; padding: 15px 10px 5px 10px;"
th:text="${#strings.arraySplit(item,'#')[1]}">
</td>
</tr>