gpt4 book ai didi

spring-boot - Thymeleaf:无法解析为表达式

转载 作者:行者123 更新时间:2023-12-03 17:26:34 26 4
gpt4 key购买 nike

我正在尝试制作一个表格,显示来自数据库的信息,包括图像。问题是如何显示图像:

<table>
<tr>
<th>ID Catégorie:</th>
<th>Nom:</th>
<th>Description:</th>
<th>Photo:</th>
</tr>
<tr th:each="cat : ${categories}">
<td><img th:src="photoCat?idCat=${cat.idCategorie}"/></td>
</tr>
</table>

我用于显示图像的 Controller 方法:
@RequestMapping(value="photoCat", produces=MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public byte[] photoCat(Long idCat) throws IOException {
Categorie c = adminCatService.getCategorie(idCat);
return org.apache.commons.io.IOUtils.toByteArray(new ByteArrayInputStream(c.getPhoto()));
}

我收到以下错误:
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "photoCat?idCat=${cat.idCategorie}" (categories:53)

你能帮忙吗?谢谢你。

最佳答案

你不能在 Thymeleaf 中嵌入这样的变量。

试试这个:

<img th:src="${'photoCat?idCat=' + cat.idCategorie}" />

关于spring-boot - Thymeleaf:无法解析为表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33270787/

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