當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringBoot 包含处理
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot 包含处理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
所有的項目開發之中頁面的相互包含是一項非常重要的技術支持,在thymeleaf模板之中提供有兩種支持語法:th:replace 是使用標簽進行替換 原始的宿主標簽還在,但是包含標簽不在th:include 是進行包含,原始的宿主標簽消失,而保留包含的標簽.<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><title>SpringBoot模板渲染</title><link rel="icon" type="image/x-icon" href="/images/favicon.ico" /><meta http-equiv="Content-Type" content="text/html;charse=UTF-8">
</head>
<body><div th:replace="@{/commons/footer}::companyInfo"></div><div th:include="@{/commons/footer}::companyInfo"></div>
</body>
</html>http://localhost/member/map<footer><p>百度(www.baidu.com)</p>
</footer><div><p>百度(www.baidu.com)</p>
</div>
1、既然要定義被包含的頁面,于是建立"src/main/templates/commons/footer.html"頁面;footer.html<meta charset="UTF-8">
<footer th:fragment="companyInfo"><p>百度(www.baidu.com)</p>
</footer>
2、隨后要進行頁面的包含處理:member_map.html<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><title>SpringBoot模板渲染</title><link rel="icon" type="image/x-icon" href="/images/favicon.ico" /><meta http-equiv="Content-Type" content="text/html;charse=UTF-8">
</head>
<body><div th:replace="@{/commons/footer}::companyInfo"></div><table><tr><td>No.</td><td>KEY</td><td>UID</td><td>姓名</td><td>年齡</td><td>偶數</td><td>奇數</td></tr><tr th:each="memberEntry,memberStat:${allUsers}"><td th:text="${memberStat.index + 1}"/><td th:text="${memberEntry.key}"/><td th:text="${memberEntry.value.mid}"/><td th:text="${memberEntry.value.name}"/><td th:text="${memberEntry.value.age}"/><td th:text="${memberStat.even}"/><td th:text="${memberStat.odd}"/></tr></table>
</body>
</html>
3、在很多的開發之中需要想被包含頁面進行參數的傳遞,于是,在thymeleaf之中也可以實現一樣的處理操作形式.使用"th:with"的處理模式完成.footer.html<meta charset="UTF-8">
<footer th:fragment="companyInfo"><p>百度(www.baidu.com)</p><p th:text="${itemid}"></p><p th:text="${subid}"></p>
</footer>而后在進行包含處理的時候可以按照如下的方式進行參數的傳遞:member_map.html<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><title>SpringBoot模板渲染</title><link rel="icon" type="image/x-icon" href="/images/favicon.ico" /><meta http-equiv="Content-Type" content="text/html;charse=UTF-8">
</head>
<body><!-- <div th:replace="@{/commons/footer}::companyInfo"></div> --><div th:include="@{/commons/footer}::companyInfo" th:with="itemid=2,subid=20"></div>
</body>
</html>百度(www.baidu.com)220
那么此時就可以利用此技術與一些其它的前端開發框架整合進行項目的編寫開發了
?
總結
以上是生活随笔為你收集整理的SpringBoot 包含处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringBoot 迭代输出
- 下一篇: SpringBoot 数据处理