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

标签 spring-boot thymeleaf

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

<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/

相关文章:

spring-boot - Thymeleaf修改并发布当前对象

java - 无法将基于 Thymeleaf 的 UI 表单中的值绑定(bind)到 Spring Boot 中的 Controller

java - 在我的 servlet 中使用 thymeleaf,找不到 html 模板文件

java - POM中有没有办法为依赖包指定更高版本?

spring-boot - 如何使用 springdoc 在 swagger openapi 规范 3.0 的 @RequestBody 中创建多个模式?

java - 解决 Thymeleaf 缺乏可选支持的问题

file - Angular2 中静态文件的默认路径是什么?

java - Spring Boot fat jar 中出现 NoClassDefFoundError 但依赖项位于已编译的存档中,并且应用程序在 IDE 中运行良好

java - 如何接受Spring boot + MVC中的任何路径

spring - 在 Spring Boot 执行器中设置 endpoints.health.sensitive=false 时无效