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

2019-03-19 17:42:16 +08:00
 571726193

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

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/546277

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX