簡體   English   中英

如何在Theamleaf中編寫String.Contains

[英]How to write String.Contains in Theamleaf

我正在寫我的if條件,但出現錯誤。 這是我正在編寫的代碼。

<th:block th:if="${#strings.contains(#obj.getTitle(), 'choice')} and ${#strings.contains(#obj.getProductTitle(), 'honey')}"></th:block>

請以這種方式編寫(在spring表達式中的變量前沒有#):

<th:block th:if="${#strings.contains(obj.getTitle(), 'choice')} and ${#strings.contains(obj.getProductTitle(), 'honey')}"></th:block>

strings.contains表達式沒有問題,實際的問題是:

#obj.getTitle()

如果您有標准的getter方法,則正確的表達式為:

${#strings.contains(obj.getTitle(), 'choice')} and ${#strings.contains(obj.getProductTitle(), 'honey')} 

或者可以是...

${#strings.contains(obj.Title, 'choice')} and ${#strings.contains(obj.ProductTitle, 'honey')}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM