关键词搜索

源码搜索 ×
×

百香菜

发布2019-01-28浏览977次

详情内容

spring boot好像喜欢采用thymeleaf(百里香叶)来做模板。

作为一个从.net过来的程序员,我觉得thymeleaf对母板页的理解不到位,甚至是发生了偏差。

thymeleaf与asp.net的razor对母板页的理解和处理,是截然不同的。

razor:
具体页套用一个母板页,将个性化内容写到母板页指定的相关区域。因此,具体页只有个性化的内容。

thymeleaf:
没有一个所谓的母板页,而是各种支离破碎的公用片段。具体页须自己去组织这些公用片段,这里引用一点,那里引用一点,缝百衲衣呢。好一个海纳百川。

大家都说它很灵活,语法很强。问你死未。

话是这么说,但我还要捏着鼻子记录一下“心得”:

话说有一个片段集合文件:_index.html,里面定义了2个公用片段:header,js

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="header">
    <meta charset="utf-8" />
    <style type="text/css">
        body{
            margin:0;
            padding:0;
            background-color: #8EACDE;
        }
    </style>
    <script th:src="@{/js/jquery-1.11.1.min.js}" src="../js/jquery-1.11.1.min.js" type="text/javascript"></script>
</head>
<body>
    <div></div>
</body>
<script th:fragment="js">
	alert("hello world!");
</script>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

好,具体页要用它们啦:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>统计结果</title>
    <th:block th:include="_index :: header" /> <!-- 引入片段header -->
    <style type="text/css">
        #container{
            height: 300px;
        }
    </style>
    <script src="http://192.168.0.211/pubzy/echarts3/echarts.min.js"></script>
</head>
<body>
    <div id="container"></div>
</body>
<script type="text/javascript">
	<th:block th:include="_index :: js" /> <!-- 引入片段js -->
</script>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

thymeleaf3.0好像有所改善,但百衲衣的核心思想并没有改变。

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载