springboot thymleaf 中 @、$、~的区别

本文详细介绍了Thymeleaf模板引擎的使用方法,包括如何引入静态文件、接收控制器传递的变量信息以及页面嵌套技巧。通过实例展示了Thymeleaf在Web开发中的强大功能。

一、引入静态文件:

@ 用于引入外部js、css文件和 form、href等请求引入指定的控制器requestMapping

<link rel="stylesheet" th:href="@{/plugins/layui/css/layui.css}">
<form th:action="@{/demo/test}" method="post" >

注:此处书写 / 是因为配置了拦截器后,造成静态资源被拦截。

二、接收controller传递来的变量信息:

$ 通常用于接收controller传递至页面的值

<input type="hidden" id="randomVal" name="randomVal" th:value="${randomVal }">

三、页面嵌入

~ 一般用户页面的嵌套

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<!-- 头部信息汇总 -->
<!-- 定义文件名称th:fragment -->
<head th:fragment="head">
<meta charset="UTF-8">
<!-- web icon -->
<link rel="shortcut icon" th:href="@{/logo.ico}" href="/logo.ico">
<!-- phone view -->
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" th:href="@{/plugins/layui/css/layui.css}" href="/plugins/layui/css/layui.css">
<link rel="stylesheet" th:href="@{/login/login.css}" href="/login/login.css">
<script th:src="@{/plugins/jQuery/jquery-2.2.3.min.js}" src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script type="text/javascript" th:src="@{/plugins/layui/layui.all.js}" src="/plugins/layui/layui.all.js"></script>
<!-- 导入bootstrap组件信息 -->
<link rel="stylesheet" th:href="@{/plugins/bootstrap/bootstrap.css}" href="/plugins/bootstrap/bootstrap.css" />
<!-- <link rel="stylesheet" th:href="@{/plugins/bootstrap/bootstrap-theme.min.css}" href="/plugins/bootstrap/bootstrap-theme.min.css" /> -->
<script type="text/javascript" th:src="@{/plugins/bootstrap/bootstrap.js}"></script>
</head>

</html>


<!-- th:include="~{html名 :: 代码名称}" -->
<head th:include="~{import :: head}"></head>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值