Spring boot:静态页面的默认本地化

时间:2016-07-27 09:34:11

标签: java spring spring-mvc

我有一个使用Spring启动的小项目(通过http://start.spring.io/创建):

1)我有一个控制器:

@Controller
public class RootController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String root() {
        return "index";
    }

}

2)在我的文件夹中:src / main / resources / static /,我添加了一个文件:index.html。

不幸的是,当我尝试通过“http://localhost:8080/”访问它时,我收到404错误。为什么?

我找到了两个解决这个问题的解决方案,但我想这不是Spring启动提出的最简单的解决方案(?):

  • 手动定义InternalResourceViewResolver的配置。
  • 在'src / main / resources / template'文件夹中移动index.html并将依赖项添加到'mustache'库。

3 个答案:

答案 0 :(得分:0)

你需要在src / main / resources / template文件夹中添加html文件。你的css和js需要在src / main / resources /文件夹里面

答案 1 :(得分:0)

您的index.html文件必须位于模板文件夹中。

enter image description here

答案 2 :(得分:0)

尝试src / main / webapp / index.html