th:fragment=”自定义片段名”
thymeleaf是一个前端模板,最近做的项目是通过springboot,angularjs,thymeleaf结合完成的。
其中thymeleaf很多功能在有js的支持下angularjs同样可以完成,比如ng-show ng-class就能达到更好的效果,而且由于angularjs是双向数据绑定的,在数据实时显示方面也表现得更好。
但是在离开js的时候纯页面交互方面使用thymeleaf就比较方便了
例如在页面中使用共同的模板:
thymeleaf提供了<</span>div th:include="common/test:: test2"></</span>div>include指令来加载共同模板test.html
看看test.html如何响应
<</span>div th:fragment="test2">对应其id名test2
同样地可以页面间可以传参,例如<</span>div th:include="common/test:: test2(value1,value2)"></</span>div>
相对的可以使用<</span>div th:fragment="test2(valueOne,valueTwo)">
本文探讨了Thymeleaf作为前端模板引擎在Spring Boot项目中的使用技巧,特别是在与AngularJS结合时的优势。文章详细介绍了Thymeleaf的自定义片段功能,以及如何在不依赖JavaScript的情况下实现页面间的模板加载和参数传递。
2628

被折叠的 条评论
为什么被折叠?



