开发者

springboot使用Thymeleaf报错常见的几种解决方案

开发者 https://www.devze.com 2022-11-29 12:12 出处:网络 作者: 没读过书的孩子
目录一、问题二、解决方法1.application.properties配置2.模板文件头3.模板文件内容一、问题我们使用springboot和Thymeleaf的时候可能会报下面的错误:Except...
目录
  • 一、问题
  • 二、解决方法
    • 1.application.properties配置
    • 2.模板文件头
    • 3.模板文件内容

一、问题

我们使用springboot和Thymeleaf的时候可能会报下面的错误:

springboot使用Thymeleaf报错常见的几种解决方案

Exception processing template “index”: An errpythonor happened during template parsing (template: “class path resource [templates/index.html]”)

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: “class path resource [tjavascript开发者_Python教程emplates/index.html]”)

二、解决方法

在springboot后端代码没有写错的前提下:

@Controller
public class HelloController {

    @RequestMapping("/")
    public String index() {
        return "index";
    }
}

1.application.properties配置

注意:一般情况下,问题不会来自于application.properties配置,默认不用配置即可,则选用模板路径为http://www.devze.com:spring.thymeleaf.prefix=classpath:/templates/

但是如果配置了该选项,修改了默认路径,记得创建对应路径。

2.模板文件头

保证html文件头为:

<!DOCTYPE html>
<html lang="en">

或者选用html约束

<!DOCTYPE html>
<html XMLns:th="http://wwww.devze.comww.thymeleaandroidf.org">

3.模板文件内容

我们在导入写好的html文件之后一般有几个问题:

1.html文件头约束,也就是上面的问题

2.html标签闭合

3.Thymeleaf的引用需要修改,如一些form表单

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

0

精彩评论

暂无评论...
验证码 换一张
取 消