java - Spring Boot v2.0 看不到模板
问题描述
我尝试启动在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 lang="en">
<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>
它给了我白标签错误。即使server.servlet.context-path=/
在resources/application.properties
如果我将文件放入resource/static
,并将文件重命名为“index.html” IndexController
,则会显示,但“name”显然不会被替换。
我做错了什么?
解决方案
最后,这个答案有所帮助。似乎它的小胡子功能。这很奇怪,因为在 SpringBoot 1.5.x 中,空文件一切正常application.properties
。如果有人知道,为什么它会更改为 SpringBoot 2.0 - 请在评论中分享。
推荐阅读
- python - 使用python时如何向xml添加附加属性
- php - "laravel Migration Foreign key constraint is incorrectly formed"
- android - nativescript - Activity restarts rather than resumes
- ios - 将长数转换为 UInt64 始终返回 nil
- java - How to unit test a kafka stream application that uses session window
- python - sqlcontext.sqlfield id 中的编码错误:IntegerType 不能接受类型中的对象 u'1'
- screen-readers - 屏幕阅读器读取列名数百次
- scala - 每次某列更改后获取一行
- lotus-notes - 是否有标记为软删除的文档的标志?
- user-interface - 从一组代码同时打开 2 个相同的窗口