Java 在条件下插入条件图像

Java 在条件下插入条件图像,java,spring,if-statement,thymeleaf,Java,Spring,If Statement,Thymeleaf,我正在尝试在Thymeleaf中执行条件: <img th:src="${{chat.sender.id} == ${#authentication.principal.user.id} ?: '/img/' + ${chat.sender.userProfile.avatar} : '/img/' + ${chat.receiver.userProfile.avatar} }"/> <img th:src="${chat.sender.id} == ${#authent

我正在尝试在Thymeleaf中执行条件:

 <img th:src="${{chat.sender.id} == ${#authentication.principal.user.id} ?: '/img/' + ${chat.sender.userProfile.avatar} : '/img/' + ${chat.receiver.userProfile.avatar} }"/>
 <img th:src="${chat.sender.id} == ${#authentication.principal.user.id} ? '/img/' + ${chat.sender.userProfile.avatar} : '/img/' + ${chat.receiver.userProfile.avatar} "/>

请解释我做错了什么。

您不应该用${}来包装整个块。同时更改?:改为?,看起来像是打字错误。 试一试


 <img th:src="${chat.sender.id} == ${#authentication.principal.user.id} ? '/img/' + ${chat.sender.userProfile.avatar} : '/img/' + ${chat.receiver.userProfile.avatar} "/>