首页 > 解决方案 > 链接到控制器的简单 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 标记内使用。

标签: javaspringapiintellij-ideathymeleaf

解决方案


原来我在创建我的 modelAndView 属性时忘记识别 viewName :

ModelAndView modelAndView = new ModelAndView("PesquisaTitulos");

推荐阅读