让我的第一个Java Spring项目使用html模板运行时遇到了麻烦。我将模板放到src/main/resources/templates中。控制器方法被成功调用。但是模板没有被调用,相反,我得到了白色标签错误:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Nov 20 19:43:09 EST 2015
There was an unexpected error (type=Not Found, status=404).
No message available有人知道我哪里做错了吗?如果我将@ResponseBody添加到控制器,它会将字符串打印到屏幕上,但我不知道如何让模板通过。谢谢。
MasterSpringMvcApplication.java
package masterSpringMvc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MasterSpringMvcApplication {
    public static void main(String[] args) {
        SpringApplication.run(MasterSpringMvcApplication.class, args);
    }
}HelloController.java
package masterSpringMvc.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/")
public class HelloController {
    public String hello() {
        System.out.println("HelloController called!");
        return "resultPage";
    }
}resultPage.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="ISO-8859-1">
    <title>Hello thymeleaf</title>
</head>
<body>
    <span th:text="|Hello thymeleaf|">Chup Html</span>
</body>
</html>build.gradle
....
dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    testCompile('org.springframework.boot:spring-boot-starter-test') 
}
....发布于 2015-11-22 14:42:46
将@RequestMapping("/")添加到控制器方法。在你的案例中-
    @RequestMapping("/")
    public String hello() {
        System.out.println("HelloController called!");
        return "resultPage";
    }https://stackoverflow.com/questions/33849630
复制相似问题