014 新的模板引擎

一.概述

  在springboot之中,抛弃了默认的thymeleaf作为模板引擎.


二 .环境的搭建

[1]配置依赖包

  我们首先需要声明的就是我们使用thymeleaf3来完成任务,比2要友好很多的.

    <properties>
        <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
        <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
    </properties>

上面的内容从springboot文档之中可以找到.

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

我们使用thymeleaf启动器来引入依赖.


三 .thymeleaf的基本使用

  在thymeleaf的默认配置之中,我们只需要将html文件放在templates文件下就能实现模板的使用.

测试代码:  

@Controller
public class ThymeleafController {
    
    @RequestMapping("/success")
    public String success() {
        return "success";
    }
}

html页面: 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    成功的到达了页面之上...
</body>
</html>

我们可以发现,我们的模板页面和之前使用的html页面是一样的.

猜你喜欢

转载自www.cnblogs.com/trekxu/p/9147678.html
014