【发布时间】:2018-02-17 18:43:37
【问题描述】:
我的问题可能很简单,我已经在使用 Spring mvc + jsp,但现在我不明白为什么控制器不返回 html 文件。现在我将 Spring Boot 与 Web 模块一起使用。
@Controller
@RequestMapping(value = "/test")
public class Main {
private static final Logger logger = Logger
.getLogger(Main.class.getName());
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String index() {
return "templates/hello.html";
}
还有我的html文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HelloWorld</title>
</head>
<body>
HELLO
</body>
</html>
我总是出错:
白标错误页面 此应用程序没有显式映射 /error,因此您将其视为后备。 2018 年 2 月 17 日星期六 20:22:24 EET 出现意外错误(类型=未找到,状态=404)。 没有可用的消息
构建文件:
buildscript {
ext {
springBootVersion = '1.5.10.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'mikhailov.diplom.ae'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
// https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf
compile group: 'org.thymeleaf', name: 'thymeleaf', version: '3.0.9.RELEASE'
}
【问题讨论】:
-
你如何称呼你的端点?