春季不显示home.html

时间:2019-06-22 06:09:49

标签: java spring spring-mvc

我正在学习Spring Framework。我在home.html中添加了resources/templates/home.html。但是当我访问http://localhost:8080时看不到它。我有以下结构:

taco-cloud \ src \ main \ java \ tacos \ TacoCloudApplication.java

package tacos;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TacoCloudApplication {

    public static void main(String[] args) {
        SpringApplication.run(TacoCloudApplication.class, args);
    }

}

taco-cloud \ src \ main \ java \ tacos \ HomeController.java

package tacos;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController 
{
    @GetMapping("/")
    public String home()
    {
        return "home.html";
    }
}

taco-cloud \ src \ main \ resources \ static \ home.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:th="http://www.thymeleaf.org">
 <head>
 <title>Taco Cloud</title>
 </head>
 <body>
 <h1>Welcome to...</h1>
 <img th:src="@{/images/TacoCloud.png}"/>
 </body>
</html>

输出

可泛白的错误页面

本地主机:8080 / home.html 显示home.html

3 个答案:

答案 0 :(得分:2)

您必须将主页的位置更改为static文件夹中:

resources/static/home.html
          ^^^^^^

代替

resources/templates/home.html

并在控制器中指定扩展名:

return "home.html";
            ^^^^^

否则,您必须创建视图解析器以避免使用扩展名,并指定页面的其他位置,请查看Configure ViewResolver with Spring Boot and annotations gives No mapping found for HTTP request with URI error

答案 1 :(得分:2)

您可以尝试一下。

account_balance - LAG(account_balance) OVER(PARTITION BY department ORDER BY timestamp ASC) delta

Check more details

答案 2 :(得分:0)

以下是在项目中放置html文件的几种不同方式。(请注意,从最高优先级到最低优先级) this.ctx = this.canvas.getContext('2d');

浏览this以获得有关spring mvc项目结构的想法