freemarker自定义标签(二)

freemarker自定义标签


1、自定义标签

      通过自定义标签,写一个重复指定字符串


2、实现源码

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>freemarker自定义标签</title>

  </head>
  
  <body>
     <#--freemarker自定义标签-->
	 <#macro repeat nums=40 name="你好">
	      <#list 1..nums as n>
	           <h1>张三,${name}${n}</h1>
	      </#list>
	 </#macro>
     
     <@repeat/>
  </body>
</html>

3、实现结果

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>freemarker自定义标签</title>

  </head>
  
  <body>
          
	           <h1>张三,你好1</h1>
	           <h1>张三,你好2</h1>
	           <h1>张三,你好3</h1>
	           <h1>张三,你好4</h1>
	           <h1>张三,你好5</h1>
	           <h1>张三,你好6</h1>
	           <h1>张三,你好7</h1>
	           <h1>张三,你好8</h1>
	           <h1>张三,你好9</h1>
	           <h1>张三,你好10</h1>
	           <h1>张三,你好11</h1>
	           <h1>张三,你好12</h1>
	           <h1>张三,你好13</h1>
	           <h1>张三,你好14</h1>
	           <h1>张三,你好15</h1>
	           <h1>张三,你好16</h1>
	           <h1>张三,你好17</h1>
	           <h1>张三,你好18</h1>
	           <h1>张三,你好19</h1>
	           <h1>张三,你好20</h1>
	           <h1>张三,你好21</h1>
	           <h1>张三,你好22</h1>
	           <h1>张三,你好23</h1>
	           <h1>张三,你好24</h1>
	           <h1>张三,你好25</h1>
	           <h1>张三,你好26</h1>
	           <h1>张三,你好27</h1>
	           <h1>张三,你好28</h1>
	           <h1>张三,你好29</h1>
	           <h1>张三,你好30</h1>
	           <h1>张三,你好31</h1>
	           <h1>张三,你好32</h1>
	           <h1>张三,你好33</h1>
	           <h1>张三,你好34</h1>
	           <h1>张三,你好35</h1>
	           <h1>张三,你好36</h1>
	           <h1>张三,你好37</h1>
	           <h1>张三,你好38</h1>
	           <h1>张三,你好39</h1>
	           <h1>张三,你好40</h1>
  </body>
</html>



原文地址:https://www.cnblogs.com/hzcya1995/p/13315036.html