java在链接到控制器的简单HTML上出现“找不到要转到的声明”错误
我正在使用Thymeleaf和springboot来创建一个crudapi
下面的代码是关于在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
在有人指出之前,我在HTML标记中使用了xmlns:th="http://www.thymeleaf.org"
# 1 楼答案
结果是,我在创建modelAndView属性时忘记了标识viewName: