spring boot集成模板引擎Thymeleaf中遇到的坑

首先,所有html文件都要放在固定路径下才能被正确读取到,/main/java/resources/templates这个路径下,而且html所有的标签必须闭合,否则启动报错

今天调用模板的时候遇到了问题,模板名为hello.html,可是访问时候一直报404,那肯定是没有正确被controller返回,所以是controller中没有写对,下面是Controller的代码

 @RequestMapping("/aaa")
    public String hello(ModelMap map) {
        // 加入一个属性,用来在模板中读取
        map.addAttribute("host", "http://blog.didispace.com");
        // return模板文件的名称,对应src/main/resources/templates/index.html
        return "hello";
    }

想在访问localhost:8080/aaa时,正确返回hello.html的话,controller的方法名返回值一定要和html同名!!!!

posted @ 2018-04-08 21:21  雪浪snowWave  阅读(478)  评论(0编辑  收藏  举报