【发布时间】:2015-07-06 18:51:52
【问题描述】:
我尝试了解 Spring Boot 如何处理 html 页面。我开始遵循指南from spring.io。本指南展示了如何使用 html 页面和查看技术 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 依赖关系对于来自src/main/resources/templates/greeting.html 的唯一HTML 页面有什么区别吗?
【问题讨论】:
-
spring-boot-starter-web是spring-boot-starter-thymeleaf的依赖项。所以thymeleaf是基于web。
标签: rest spring-boot dependency-management