【问题标题】:"Cannot find declaration to go to" error on a simple HTML linking to a controller链接到控制器的简单 HTML 中的“找不到要转到的声明”错误
【发布时间】:2021-02-09 00:45:00
【问题描述】:

我正在使用 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

在有人指出之前,我在 HTML 标记中使用了xmlns:th="http://www.thymeleaf.org"

【问题讨论】:

    标签: java spring api intellij-idea thymeleaf


    【解决方案1】:

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

    ModelAndView modelAndView = new ModelAndView("PesquisaTitulos");
    

    【讨论】:

      猜你喜欢
      • 2022-12-15
      • 2012-08-27
      • 2011-08-19
      • 1970-01-01
      • 2020-12-05
      • 2011-03-26
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      相关资源
      最近更新 更多