V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
571726193
V2EX  ›  Java

springboot2.1.0+thymeleaf 整合 问题如下:死活进不去,大哥们求助,我 QQ571726193,或者留言,提前谢过

  •  
  •   571726193 · 2019-03-19 17:42:16 +08:00 · 8867 次点击
    这是一个创建于 1836 天前的主题,其中的信息可能已经有所发展或是发生改变。

    ##Springboot+thymeleaf 整合问题 ##接口

    @Controller
    public class HelloController {
    
    @Autowired
    private ApiLogService apiLogService;
    
    @RequestMapping("/getLog")
    public String getLog(Model model) {
        model.addAttribute("apiLogList",apiLogService.getList());
        return "list";
      }
    }
    

    ##页面错误信息

    This application has no explicit mapping for /error, so you are seeing this as a fallback.
    Tue Mar 19 17:31:23 CST 2019
    There was an unexpected error (type=Internal Server Error, status=500).
    Error resolving template [getLog], template might not exist or might not be accessible by any of the configured 
    Template Resolvers
    org.thymeleaf.exceptions.TemplateInputException: Error resolving template [getLog], template might not exist 
    or might not be accessible by any of the configured Template Resolvers at。。。
    

    ##后台错误信息

    org.thymeleaf.exceptions.TemplateInputException: Error resolving template [getLog], template might not exist 
    or might not be accessible by any of the configured Template Resolvers
    

    ##页面目录

    templates/list.html
    

    ##配置信息(仅此一个关于 thymeleaf 的配置)

    spring.thymeleaf.cache=false
    
    9 条回复    2019-03-20 11:12:08 +08:00
    wineast
        1
    wineast  
       2019-03-19 18:10:40 +08:00
    看日志是 resover 的配置问题,controller 返回的“ list ”字符串,无法定位到“ template/list.html ”
    MrAQL
        2
    MrAQL  
       2019-03-19 19:43:13 +08:00
    spring:
    thymeleaf:
    cache: false
    model: HTML5
    prefix: classpath:/templates/
    suffix: .html
    你可以指定下模板路径看看可不可以
    yiyi11
        3
    yiyi11  
       2019-03-19 19:52:27 +08:00 via Android
    不知道为啥,看到留 qq 就觉得很 low。
    huruwo
        4
    huruwo  
       2019-03-19 21:00:44 +08:00
    @yiyi11 这是病
    Betsy
        5
    Betsy  
       2019-03-19 21:09:14 +08:00 via iPhone
    楼主如果使用的是 maven 管理的话,大概率在 pom.xml 中少写了一条与 thymeleaf 相关的依赖,名字应该为 spring-boot-starter-thymeleaf
    tt0411
        6
    tt0411  
       2019-03-19 21:56:45 +08:00
    public String getLog(Model model) 方法前加个注解 @ResponseBody
    nita22
        7
    nita22  
       2019-03-20 08:48:27 +08:00
    跟 5 楼说的一样,先看看依赖有没有引错。另外,规范一点的话,@RequestMapping 里面还是把对应的方法给填上吧
    Junwwwww
        8
    Junwwwww  
       2019-03-20 09:06:44 +08:00
    templates 在 resources 目录下吗?
    notreami
        9
    notreami  
       2019-03-20 11:12:08 +08:00
    @RequestMapping("/getLog")
    public ModelAndView getLog(ModelAndView mv) {
    mv.setViewName("/list");
    mv.addObject("apiLogList",apiLogService.getList());
    return mv;
    }
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3270 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:08 · PVG 22:08 · LAX 07:08 · JFK 10:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.