Thymeleaf th:班级条件

时间:2017-09-18 13:22:36

标签: java thymeleaf

我写了这个条件并且不起作用:

<fieldset class="rating">
    <span class="course-view-rating bigger">
        <label th:class="${feedback.message.rating &ge; 5}? 'active'" for="rating5"></label>
        <label th:class="${feedback.message.rating &ge; 4}? 'active'" for="rating4"></label>
        <label th:class="${feedback.message.rating &ge; 3}? 'active'" for="rating3"></label>
        <label th:class="${feedback.message.rating &ge; 2}? 'active'" for="rating2"></label>
        <label th:class="${feedback.message.rating &ge; 1}? 'active'" for="rating1" ></label>
    </span>
</fieldset>

feedback.message.rating的值始终是0到5之间的数字。

使用:

  • Spring 4.3
  • Java 1.8
  • Thymeleaf 3.0.7 ***

这是错误消息:

Servlet.service() for servlet [thymeleafDispatcherServlet] in context with path [/frontend-th] threw exception 
    [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: 
    Exception evaluating SpringEL expression: "feedback.message.rating ? 1" (template: "pages/eventdetail" - line 179, col 52)] with root cause
    java.lang.IllegalStateException: Cannot handle (8805) '?'

感谢您的回复

2 个答案:

答案 0 :(得分:0)

这是有效的,我不明白为什么:D:D

<label th:class="${feedback.message.rating >= 5}? 'active'" for="rating5"></label>

答案 1 :(得分:0)

您应该尝试这个

class NewUserTest(LiveServerTestCase):

    def setUp(self):
        self.browser = webdriver.Firefox()
        self.browser.implicitly_wait(15)

    def tearDown(self):
        self.browser.quit()

...