thymeleaf 常用

<html lang="en" xmlns:th="http://www.thymeleaf.org">

*文本text区别

<!--区别一个不可以解析标签,-->
<h1 th:text="${title}">欢迎</h1>
<!--区别一个可解析标签-->
<h1 th:utext="${title}">欢迎</h1>

*循环获取 text的值

<h3 th:each="name:${data}" th:text="${name}">在这显示名字</h3>

*处理网址

<a href="" th:href="@{/user}">点我</a>

*a 标签的连接写法
在配置文件中配置通用地址

server.servlet.context-path=/dev

a 标签会自动在前面加上这个地址

<!--连接写法-->
<!--这种写法会在前面自动拼接context-path-->
<a href="" th:href="@{/dep/list}">对的链接/dep/list</a>

*form表单

<form action="" th:action="@{/user}">
    <input type="text" name="" th:value="${name}">
</form>

*fragment 与replace, include

fragment 是写通用片段的 创建一个html 专写它
```

<h1>首页</h1>
在其他页面调取

:replace 与include 的区别

```

猜你喜欢

转载自www.cnblogs.com/lxx-1843693653/p/11110602.html