这可能听起来像是一个琐碎的问题,但是经过数小时的搜索,我仍然找不到答案。据我所知,问题在于我试图从控制器返回一个 FileSystemResource ,而Thymeleaf期望我提供一个
String资源,以便它将呈现下一页。但由于我正在返回一个
FileSystemResource,因此我收到以下错误:
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "products/download", template might not exist or might not be accessible by any of the configured Template Resolvers
我使用的控制器映射是:
@RequestMapping(value="/products/download", method=RequestMethod.GET)
public FileSystemResource downloadFile(@Param(value="id") Long id) {
Product product = productRepo.findOne(id);
return new FileSystemResource(new File(product.getFileUrl()));
}
我的HTML链接看起来像这样:
<a th:href="${'products/download?id=' + product.id}"><span th:text="${product.name}"></span></a>
我不希望被重定向到其他地方,我只需要在链接被点击后下载文件。这是否是正确的实现方式?我不确定。
$
应该改成@
,你可以试一下这种方式吗? - mtyurt