thymeleaf模板引擎的使用

1.什么是thymeleaf

thymeleaf是页面模板引擎。类似于JSP


2.为什么使用thymeleaf

随着springboot的愈加流行,传统的使用JSP开发页面可能存在一些问题。

springboot 提供了一些模板引擎,thymeleaf, freemarker,velocity 等供我们选择。

其中因thymeleaf对spring MVC的良好支持,springboot推荐用thymeleaf作为模板引擎。


3.如何使用

  1. 引入依赖

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

2.在html页面中引用

静态资源存放在 static 目录下

<!DOCTYPE html>
<html lang="zh-CN"  xmlns="http://www.w3.org/1999/xhtml"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>thymeleaf的使用</title>
    <link th:href="@{/css/animate.css}" rel="stylesheet" type="text/css" />
 
    <script th:src="@{/js/common/jquery.min.js}"></script>

    <script th:inline="javascript">
           $(document).ready(function(){
               var data = [[${result} ]] ; //js中获取后台传回来的数据
	       alert(data);	
           });
    </script>
</head>

注意标签要闭合,布套后台处理时会报错。


3.后台通过springboot 使用@RestController 返回字符串即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值