Я пытаюсь понять, как весенняя загрузка работает с html-страницами. Я начал следовать руководству from spring.io. В этом руководстве показано, как работать с html-страницей и просматривать технологию Thymeleaf. Он имеет страницы:spring-boot-starter-web vs spring-boot-starter-thymeleaf
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>
Я изменил его простой
<!DOCTYPE HTML>
<html>
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Hello
</body>
</html>
И следующие spring boot reference documentation изменилось spring-boot-starter-thymeleaf
(что не нужно сейчас), чтобы spring-boot-starter-web
, после того, что я не могу видеть веб-страницы. Я вижу результат:
There was an unexpected error (type=Not Found, status=404).
No message available.
Когда я вернулся мой Gradle зависимости thymeleaf
все работает отлично.
Контроллер src/main/java/hello/GreetingController.java
package hello;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class GreetingController {
@RequestMapping("/greeting")
public String greeting() {
return "greeting";
}
}
Применение src/main/java/hello/Application.java
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Может кто-нибудь объяснить мне, что разница между web
и thymeleaf
зависимостей для этого только HTML страницы из src/main/resources/templates/greeting.html
?
'spring-boot-starter-web' является зависимостью от' spring-boot-starter-thymeleaf'. Поэтому 'тимелеар' основан на' web'. – alexvetter