【发布时间】:2020-08-05 23:18:18
【问题描述】:
我想根据条件在百里香中分配一个变量:
<span th:with="valueID=${${myField != null} ? {myField.value.getId()}}">
这不起作用,并给了我一个例外:
"Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: `"${myField == null} ? {myField.value.getId()}"`"
我做错了什么?
实际上我想在 myField 不是 null 时将 valueID 设置为 {myField.value.getId()}。
【问题讨论】:
-
这对我有用——不是 Spring 方言,只是标准 Thymeleaf 方言(Spring 可能有另一种方法):
<span th:with="valueID=${myField != null} ? ${myField.value.id} ">。它假设您有value和id的相关吸气剂。当myField为空时,你想发生什么?您也可以使用完整的? :运算符。
标签: java spring spring-boot spring-mvc thymeleaf