gpt4 book ai didi

java - Thymeleaf 条件图像在条件下插入

转载 作者:行者123 更新时间:2023-12-02 09:27:02 34 4
gpt4 key购买 nike

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

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

但是我收到错误:

Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "{chat.sender.id} == ${#authentication.principal.user.id} ?: '/img/' + ${chat.sender.userProfile.avatar} : '/img/' + ${chat.receiver.userProfile.avatar} " (template: "chat/friends-chat" - line 28, col 18)

请解释一下我做错了什么。

最佳答案

您不应该将整个 block 包裹在 ${ } 中。另外将 ?: 更改为 ?,看起来像是一个错字。尝试使用

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

关于java - Thymeleaf 条件图像在条件下插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58271536/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com