appstore54321
V2EX  ›  Java

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

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