2016-03-08 63 views
3

我試圖把邊框顏色爲紅色,如果學生是通過使用下面的表達式如何通過次使用內聯CSS:樣式使用「?:運算符」在ThymeLeaf

<div class="image_wrap" th:style="${student.studentExamStatus}?border-style: solid;border-color: red;:"> 

失敗,但我得到以下異常 請求處理失敗;嵌套的例外是org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "${student.studentExamStatus}?border-style: solid;border-color: red;:"

$ {student.studentExamStatus}將返回0或1的學生通過考試或不。

+1

認爲您需要將您的樣式語句嵌套在單引號中。否則,Thymeleaf將嘗試以運營商的方式對待冒號。 – Andrew

回答

4

正如@安德魯所說,你需要將你的風格語句嵌套在單引號中。並且您必須在括號內包含您的表達式:

<div class="image_wrap" th:style="${student.studentExamStatus ? 'border-style: solid;border-color: red;' : ''}">