1,错误
An error happened during template parsing (template: “class path resource [templates/index.html]”)
2.代码修改
我自己的Java代码是正确的,只是视图层的问题!
下面就是我一开始的部分前端代码:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="_fragments :: head(~{::title})">
然后运行就报了500错误:控制台为:
2021-07-05 21:02:47.331 ERROR 13076 --- [nio-8080-exec-3] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-3] Exception processing template "index": An error happened during template parsing (template: "class path resource [templates/index.html]" - line 579, col 60)
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/index.html]" - line 579, col 60)
然后也是百度了好一会儿才解决的,总之就是坚信自己的Java服务层代码没错!
解决方法:
就是把xml namespace(命名空间)代码删除:
删除之后的代码为:
<!DOCTYPE html>
<html lang="en">
<head replace="_fragments :: head(~{::title})">
记得把带有th:
的代码都删除掉,之后要用的时候再添加条件再加上
3.总结
记得出现该错误的时候,如果你对前端知识不太了解,坚信自己的Java服务层代码无误的情况下那么请相信自己,欸,也许我是对自己的Java技术不太自信吧(的确技术页不好,哈哈)!
坚信自己就是静态资源导入的代码出错,和Java代码不匹配。
我自己就是遇见这个问题浪费了好多时间,希望对大家有所帮助!