0
我對Thymeleaf有點新,所以如果這是newb語法錯誤,請致歉。 我正試圖讓Thymeleaf在同一個th:with
屬性中執行多個語句。評估Thymeleaf屬性中的多個表達式
<div th:with="url = ${#httpServletRequest.getRequestURL()}, url = ${url.substring(0, url.indexOf('error'))}"></div>
但是這不是正確的語法。
org.thymeleaf.exceptions.TemplateProcessingException:無法解析爲賦值序列:「url = $ {#httpServletRequest.getRequestURL()},url = url.substring(0,url.indexOf('error'))」 (錯誤/ 404:11)
這是可能的,如果是這樣,我想完成什麼正確的語法?
編輯:在我已經修復的部分中出現了一個語法錯誤,現在我得到了一個不同的錯誤。
嘗試將它分成兩部分,但是看起來url
變量未在SpringEL表達式中正確填充。
<div th:with="url = ${#httpServletRequest.getRequestURL()}">
<div th:with="url = ${url.substring(0, url.indexOf('error'))}"></div>
</div>
org.thymeleaf.exceptions.TemplateProcessingException:無法解析作爲分配序列: 「URL = $ {url.substring(0,url.indexOf( '錯誤')})」(錯誤/ 404: 12)
引起:java.lang.StringIndexOutOfBoundsException:字符串索引超出範圍:-1
嘗試不帶空格也許:) – ACV
你會得到什麼錯誤? – ACV
我不認爲你的第二個例子有什麼問題。如果您的url變量中沒有字符串「error」,則返回-1,這會導致** url.substring **失敗,並顯示錯誤信息。 – Metroids