我尝试启动在Spring Initializr中创建的演示应用程序。Spring Boot版本-2.0.3。
我创建了index.html并将其放入resources/templates文件夹中。当我启动时spring-boot:run,控制台状态中的消息之一:
Tomcat started on port(s): 8080 (http) with context path ''
当我打开时localhost:8080,它给了我Spring的Whitelabel错误页面
我试图server.servlet.context-path=/在resources/application.properties文件中添加行。但这无济于事。
如何为索引设置正确的路径?
UPD:似乎问题仅在于模板部分。
内容index.html在resources/templates:
<!DOCTYPE html>
<html>
<body>
<h1>Hello {{ name }}!!!</h1>
</body>
</html>
内容IndexController.java:
@Controller
public class IndexController {
@GetMapping("/")
public ModelAndView index() {
Map<String, String> model = new HashMap<>();
model.put("name", "world");
return new ModelAndView("index", model);
}
我在使用胡子pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mustache</artifactId>
</dependency>
<dependency>
它给了我whitelabel错误。即使server.servlet.context-path=/在resources/application.properties
如果将文件放在中resource/static,然后在中将文件重命名为“ index.html” IndexController,则会显示该文件,但显然不会替换“名称”。
我做错了什么?
海绵宝宝撒
相关分类