【发布时间】:2018-06-16 08:27:36
【问题描述】:
所以我尝试按照使用 devtools+mustache+data-jpa 的简单 Spring Boot 项目的说明进行操作。我只是复制粘贴整个东西,它不起作用,即使教程说“只需按下按钮,它就可以工作”。完整源代码here,最后会提供一些清单。
我要做的就是从 localhost:8080/ 重定向到 index.html 并将简单的值插入到模板中。
但是:
1. 出于某种原因,某些东西将我从 / 重定向到 /apex/f?p=4950:1
2. 如果我将映射更改为 @GetMapping("/home") 并尝试 localhost:8080/home 我得到 404
启用日志记录后,我发现 PathResourceResolver 不会扫描 /resources/templates 目录。如果我添加对 Thymeleaf 的依赖,它会找到它。
所以问题是问题出在哪里?我应该添加一些配置文件吗?还是 Mustache 不是那样工作的?
IndexController.java
@Controller
public class IndexController {
@GetMapping("/")
public ModelAndView home() {
Map<String, String> model = new HashMap<>();
model.put( "name", "Alex" );
return new ModelAndView( "index", model );
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>Welcome to Spring, {{ name }}</h1>
</body>
</html>
依赖关系
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-mustache')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
结构
日志
【问题讨论】:
标签: java spring spring-boot mustache