【发布时间】:2015-10-10 18:39:18
【问题描述】:
POM
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
应用
@SpringBootApplication
public class Application {
public static void main(String args[]){
SpringApplication.run(Application.class);
}
}
控制器
@Controller
@RequestMapping("/index")
public class IndexController {
@RequestMapping("/")
String index(){
return "index";
}
}
我在资源文件夹和 error.html 和 index.html 中有模板文件夹
当我访问 localhost:8080/index 时,会显示错误而不是索引。我究竟做错了什么?这确实是最简单的设置,但它已经错了......
【问题讨论】:
-
你有application.properties文件吗?
-
我没有,没必要
-
您应该访问 localhost:8080/index/ (带有斜杠),因为您请求了它。或者去掉方法级映射@RequestMapping("/")。
标签: spring spring-boot thymeleaf