#java #spring #api #intellij-idea #thymeleaf
#java #весна #API #intellij-idea #thymeleaf
Вопрос:
Я использую 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.
Ответ №1:
Оказывается, я забыл указать viewName при создании моего атрибута ModelAndView :
ModelAndView modelAndView = new ModelAndView("PesquisaTitulos");