2016-02-27 349 views
4

我有像wange/25011.jpg|wange/25011-1.jpg或null的imageName,我想將它們拆分爲wange/25011.jpgwange/25011-1.jpg,或者如果爲null,則不拆分。我想下面的代碼,但沒有工作......如何在Thymeleaf中拆分字符串

<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

我自己得到了答案。 – mikezang

+0

請您添加一個答案,告訴我們您做了什麼來解決您的問題? –

回答

5

這是我自己的答案:

<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>