学习springboot + thymeleaf 遇到的问题

调用接口的时候 项目一直报错: org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/thymeleaf/user", template might not exist or might not be accessible by any of the configured Template Resolvers

请问一般什么问题?

阅读 3.1k
3 个回答

对于springboot,解析页面时,默认从resources 中的templates文件夹下寻找界面解析。

并且对于使用thymeleaf模板引擎,它要求写的HTML要严格按照HTML的格式,
如:
单标签一定要有\

<br\>

路径问题,提示模板文件访问不到

如果是使用 spring-boot-starter-thymeleaf,可以添加下列配置在application.properties

spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题