Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring thymileaf:如果属性和属性存在,则显示文本_Spring_Thymeleaf_Spring El - Fatal编程技术网

Spring thymileaf:如果属性和属性存在,则显示文本

Spring thymileaf:如果属性和属性存在,则显示文本,spring,thymeleaf,spring-el,Spring,Thymeleaf,Spring El,如果属性和属性存在,在thymeleaf中是否有一种简单的方法来显示属性的内容?如果在我的html页面中有一个属性“error”和属性“summary”,我想显示它: <span th:text="${error.summary}">error summary</span> 有没有更简单的方法来实现这一点?当然!由于与th:if属性关联的处理器的值大于与th:text属性关联的值,因此将首先对其进行计算。因此,你可以写: <span th:if="${error

如果属性和属性存在,在thymeleaf中是否有一种简单的方法来显示属性的内容?如果在我的html页面中有一个属性“error”和属性“summary”,我想显示它:

<span th:text="${error.summary}">error summary</span>

有没有更简单的方法来实现这一点?

当然!由于与
th:if
属性关联的处理器的值大于与
th:text
属性关联的值,因此将首先对其进行计算。因此,你可以写:

<span th:if="${error != null && error.summary != null}" th:text="${error.summary}">Static summary</span>
静态摘要
您甚至可以使用以下方法缩短它:

<span th:text="${error?.summary}">Static summary</span>
静态摘要
但我认为在这种情况下,无论摘要是否存在,都会创建span标记,这有点难看


查看有关条件表达式的详细信息。

Tanks。这正是我要查找的内容。@tduchateau如果不需要对条件表达式进行标记,我们可以使用
th:remove=“tag”
?指向条件表达式的链接不起作用。
<span th:text="${error?.summary}">Static summary</span>