571726193
V2EX  ›  Java

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

  •  
  •   571726193 · Mar 19, 2019 · 10274 views
    This topic created in 2799 days ago, the information mentioned may be changed or developed.

    ##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 replies  •  2019-03-20 11:12:08 +08:00
    wineast
    wineast
    Mar 19, 2019
    1
    看日志是 resover 的配置问题,controller 返回的“ list ”字符串,无法定位到“ template/list.html ”
    MrAQL
    MrAQL
    Mar 19, 2019
    2
    spring:
    thymeleaf:
    cache: false
    model: HTML5
    prefix: classpath:/templates/
    suffix: .html
    你可以指定下模板路径看看可不可以
    yiyi11
    yiyi11
    Mar 19, 2019 via Android
    3
    不知道为啥,看到留 qq 就觉得很 low。
    huruwo
    huruwo
    Mar 19, 2019
    4
    @yiyi11 这是病
    Betsy
    Betsy
    Mar 19, 2019 via iPhone
    5
    楼主如果使用的是 maven 管理的话,大概率在 pom.xml 中少写了一条与 thymeleaf 相关的依赖,名字应该为 spring-boot-starter-thymeleaf
    tt0411
    tt0411
    Mar 19, 2019
    6
    public String getLog(Model model) 方法前加个注解 @ResponseBody
    nita22
    nita22
    Mar 20, 2019
    7
    跟 5 楼说的一样,先看看依赖有没有引错。另外,规范一点的话,@RequestMapping 里面还是把对应的方法给填上吧
    Junwwwww
    Junwwwww
    Mar 20, 2019
    8
    templates 在 resources 目录下吗?
    notreami
    notreami
    Mar 20, 2019
    9
    @RequestMapping("/getLog")
    public ModelAndView getLog(ModelAndView mv) {
    mv.setViewName("/list");
    mv.addObject("apiLogList",apiLogService.getList());
    return mv;
    }
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2387 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 04:54 · PVG 12:54 · LAX 20:54 · JFK 23:54
    ♥ Do have faith in what you're doing.