appstore54321
V2EX  ›  Java

Spring Restful initializr 生成项目的 html 文件该放在哪?

  •  
  •   appstore54321 · Dec 27, 2016 · 2723 views
    This topic created in 3490 days ago, the information mentioned may be changed or developed.

    这是项目文件结构,从 initializr 官网上直接下载的,和网上其他 spring 教程的区别是,没有 webapp 文件夹,没有 public 文件夹,没有 web.xml, servlet.xml ,总之就是什么都没有...而且官方的教程只讲到返回 json 数据,我现在想在"/"地址显示一个 index.html 页面,但是

      @RequestMapping(value = "/")
        public ModelAndView root() {
            ModelAndView view = new ModelAndView("index");
            return view;
        }
        或者
        @RequestMapping(value = "/")
        public ModelAndView root() {   
            return "index";
        }
    

    都只是返回字符串"index",而找不到这个文件,不管 index.html 放在 static 还是 template ,有人说这是因为 @RestController 默认返回 responbody ,但是 restful 只能用这种 controller 啊。后来我参考别的项目加了 webapp 文件,按照 jsp 的方法设置也还是不行。所以比较崩溃,想问一下有什么解决方案吗?

    Miy4mori
        1
    Miy4mori  
       Dec 27, 2016 via Android
    请仔细阅读 spring boot reference 并搞清楚 spring boot 中 fat jar 和 war 两种打包方式的区别。
    qinxi
        2
    qinxi  
       Dec 28, 2016 via Android
    src/main/resources/template 是默认模板路径 纯 html 可以放 static 目录,
    S1ahs3r
        3
    S1ahs3r  
       Dec 28, 2016
    在官方 refrence 最下面有一份配置文件模板.看一下 default 值就好了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1217 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 17:43 · PVG 01:43 · LAX 10:43 · JFK 13:43
    ♥ Do have faith in what you're doing.