SpringBoot项目访问HTML页面

引入相关依赖



    org.springframework.boot
    spring-boot-starter-thymeleaf

    UTF-8
    UTF-8
    1.8
    
    3.0.2.RELEASE
    2.0.5

增加springboot配置项

#thymeleaf模版前缀
spring.thymeleaf.prefix=classpath:/templates/

在 src/main/resources 目录下新建 static 目录和 templates 目录。 static存放静态文件,templates 存放静态页面(thymeleaf 模版)

SpringBoot项目访问HTML页面_第1张图片

在控制器中写明跳转模版方法

SpringBoot项目访问HTML页面_第2张图片

 

Handler访问映射地址跳转模版成功

总结这次遇到的问题:

1. Error resolving template template might not exist or might not be accessible

控制器方法返回的模版名称没有前缀/,可手动添加/或添加springboot配置项

2. org.xml.sax.SAXParseException: 元素类型 “link” 必须由匹配的结束标记 “” 终止,org.xml.sax.SAXParseException: 元素类型 “meta” 必须由匹配的结束标记 “” 终止

开发工具生成的html页面元素有的没有终止符/,thymeleaf模板引擎默认是Template modes:HTML5解析的,解析比较严格。

需要手动添加/或指定引入的thymeleaf版本号

SpringBoot项目访问HTML页面_第3张图片

你可能感兴趣的:(配置项,Java)