##Springboot+thymeleaf 整合问题 ##接口
@Controller public classHelloController { @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
1 wineast 2019-03-19 18:10:40 +08:00 看日志是 resover 的配置问题,controller 返回的“ list ”字符串,无法定位到“ template/list.html ” |
![]() | 2 MrAQL 2019-03-19 19:43:13 +08:00 spring: thymeleaf: cache: false model: HTML5 prefix: classpath:/templates/ suffix: .html 你可以指定下模板路径看看可不可以 |
![]() | 3 yiyi11 2019-03-19 19:52:27 +08:00 via Android 不知道为啥,看到留 qq 就觉得很 low。 |
![]() | 5 Betsy 2019-03-19 21:09:14 +08:00 via iPhone 楼主如果使用的是 maven 管理的话,大概率在 pom.xml 中少写了一条与 thymeleaf 相关的依赖,名字应该为 spring-boot-starter-thymeleaf |
![]() | 6 tt0411 2019-03-19 21:56:45 +08:00 public String getLog(Model model) 方法前加个注解 @ResponseBody /td> |
7 nita22 2019-03-20 08:48:27 +08:00 跟 5 楼说的一样,先看看依赖有没有引错。另外,规范一点的话,@RequestMapping 里面还是把对应的方法给填上吧 |
8 Junwwwww 2019-03-20 09:06:44 +08:00 templates 在 resources 目录下吗? |
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; } } |