java - 链接到控制器的简单 HTML 中的“找不到要转到的声明”错误
问题描述
我正在使用 Thymeleaf 和 Spring Boot 来创建一个 CRUD API。
下面的代码是关于在 HTML 文件上创建表格的:
<tr th:each="titulo : ${titulos}" th:value="titulo">
<td class="text-center" th:text="${titulo.codigo}">1</td>
<td class="text-center" th:text="${titulo.descricao}"></td>
<td class="text-center" th:text="${titulo.dataVencimento}"></td>
<td class="text-center" th:text="${titulo.valor}"></td>
<td class="text-center" th:text="${titulo.status.descricao}"></td>
<td class="text-center">
以下是控制器类中关于上面声明的属性“titulos”的代码:
@RequestMapping
public ModelAndView pesquisar() {
List<Titulo> todosTitulos = titulosRepository.findAll();
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("titulos", todosTitulos);
return modelAndView;
}
我不知道为什么会出现以下错误:
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [titulos], template might not exist or might not be accessible by any of the configured Template Resolvers
在有人指出之前,我xmlns:th="http://www.thymeleaf.org"
在 HTML 标记内使用。
解决方案
原来我在创建我的 modelAndView 属性时忘记识别 viewName :
ModelAndView modelAndView = new ModelAndView("PesquisaTitulos");
推荐阅读
- android - 如何使用 OkHttpClient 在 Kitkat 上下载 apk 文件
- azure - MarkLogic - 我们可以在 Azure Blob 上配置计划备份吗
- ios - “未定义的符号:_OBJC_CLASS__$_LCOpenSDK_PlayWindow”出错
- android - 尝试从 URI 上传图像文件时,该位置不存在对象
- linux - Electron breakpad minidump 版本不匹配
- eclipse - 使用 Eclipse 搜索的“OR”正则表达式
- c# - 两种语言的机器人
- sql-server - 为 BCP 实用程序创建查询时出现单引号问题
- linux - 如何根据标签将单个 XML 文件拆分为多个
- android - 如何将增量构建添加到 Dagger 2