spring-boot - Spring Boot 看不到小胡子模板
问题描述
我在 Spring Boot 上有一个非常简单的应用程序。它只是一个控制器和胡子模板。
package io.github.aleksejshherbak.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/")
public String index() {
return "index";
}
}
模板只是简单的标记
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Person keeper</title>
</head>
<body>
<h1>Lorem ipsum dolor sit amet.</h1>
</body>
</html>
我在 gradle 的帮助下安装了 mustache。我的构建文件是
plugins {
id 'java'
// Apply the application plugin to add support for building an application
id 'application'
id 'org.springframework.boot' version '2.1.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
}
mainClassName = 'io.github.aleksejshherbak.App'
group 'io.github'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.guava:guava:23.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// https://mvnrepository.com/artifact/com.github.spullara.mustache.java/compiler
compile group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.8.9'
}
但是当我启动它并在我的浏览器中输入时,我遇到了localhost:8080/
404 错误。怎么了?
解决方案
只需添加依赖项:
implementation 'org.springframework.boot:spring-boot-starter-mustache'
并配置application.properties
小胡子:
spring.mustache.prefix=classpath:/templates/
spring.mustache.suffix=.mustache
推荐阅读
- python - 如何按嵌套注释字段排序?
- python - Pandas - 向 DF href 添加一列
- excel - 结合 COUNTIF 和 VLOOKUP
- javascript - Ionic 3 使用网格在右侧离子输入内部带有图标
- java - 区块链技术如何验证工作量证明
- javascript - Angular 6 中的动态属性评估
- apache-kafka - Apache Nifi 中的 publishKafka 处理器中的多个 kafka 主题
- python - Python:有点请求
- jquery - 解析通过jquery中的ajax获得的json响应后如何进行foreach?
- java - 不幸的是,应用程序已停止并导致 E/installd: system dir 0 : /system/app/