码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-04-08 22:32:00      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:templates   color   mapping   启动   boot   elm   class   temp   必须   

首先,所有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同名!!!!

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

标签:templates   color   mapping   启动   boot   elm   class   temp   必须   

原文地址:https://www.cnblogs.com/team42/p/8747576.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!