Как отрендерить html документ в Spring
Есть код:
package com.example.here.controller;
import com.example.here.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@Controller
public class MainController {
@GetMapping("/")
public String main(Model model) {
return "main";
}
}
main.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>You are in main page</h1>
</body>
</html>
В гайде из ютуба при переходе на localhost:8080 рендериться main.html, но почему-то этого не произошло. main.html находится в resources/templates/main.html
Вместо рендеринга выдаётся ошибка:
Ответы (1 шт):
Автор решения: Foge
→ Ссылка
Предположу, что в том гайде в зависимостях был добавлен thymeleaf. В maven это делается добавлением в файл pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>3.2.3</version>
</dependency>
</dependencies>