我想在Spring Boot 2.0.3应用程序中呈现AJAX响应。不幸的是,仅渲染片段时,Thymeleaf看不到传递的模型属性。
我的控制器是:
@PostMapping(DOWNLOAD_URL + "ajax")
public String downloadAjax(@ModelAttribute DownloadDto downloadDto, Model model) {
log.debug("Received ajax download request");
List<Download> downloads = downloadService.download(downloadDto);
model.addAttribute("downloads", downloads);
return "ajax :: ajaxResponse";
}
而ajax.html是:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="de">
<head>
</head>
<body>
<table>
<tbody>
<th:block th:fragment="ajaxResponse">
<th:block th:each="download : ${downloads}">
<tr th:replace="downloadRow :: downloadTemplate (templateId=${download.id},templateTitle=${download.title},templateProgress=${download.progress})"></tr>
</th:block>
</th:block>
</tbody>
</table>
</body>
</html>
不幸的是,IntelliJ已经抱怨无法解决第9行中的下载。这与Thymeleaf integration with Spring (Part 2)中的基本相同,但不知何故。如果我删除片段并直接渲染文件,它将起作用。