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>

freemarker自定义标签(二)

时间: 2024-09-30 06:52:44

freemarker自定义标签(二)的相关文章

freemarker自定义标签报错(二)

freemarker自定义标签 1.错误描述 freemarker.core.ParseException: Unexpected end of file reached. at freemarker.core.FMParser.generateParseException(FMParser.java:4702) at freemarker.core.FMParser.jj_consume_token(FMParser.java:4573) at freemarker.core.FMParser

freemarker自定义标签报错(八)

1.错误描述 freemarker.core.ParseException: Token manager error: freemarker.core.TokenMgrError: Unknown directive: #assgin on line: 18, column: 151, in template: tag.ftl in tag.ftl at freemarker.template.Template.<init>(Template.java:174) at freemarker.c

freemarker自定义标签报错(三)

freemarker自定义标签 1.错误描述 freemarker.core.ParseException: Encountered " " at line 14, column 12 in myself.ftl. Was expecting one of: <STRING_LITERAL> ... <RAW_STRING> ... "false" ... "true" ... <INTEGER> ... &l

freemarker自定义标签

freemarker自定义标签 1.自定义标签说明 宏变量存储模板片段可以被用作自定义指令macro 2.示例说明 <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>freemarker自定义标签</title> </head> <body> <#--

freemarker自定义标签报错(四)

freemarker自定义标签 1.错误描述 六月 05, 2014 11:31:35 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template processing error: "Error executing macro: write\nrequired parameter: nums is not specified." Error executing macro: write required pa

freemarker自定义标签(三)-nested指令

freemarker自定义标签 1.nested指令 是可选的,可以在<#macro>和</#macro>之间使用在任何位置和任意次数 2.示例说明 <#macro tag> <#nested/> </#macro> <@tag> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li>

freemarker自定义标签报错(七)

1.错误描述 六月 09, 2014 11:11:09 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template processing error: "Expression a is undefined on line 27, column 23 in tag.ftl." Expression a is undefined on line 27, column 23 in tag.ftl. The probl

freemarker自定义标签报错(一)

freemarker自定义标签 1.错误描述 freemarker.core.ParseException: Token manager error: freemarker.core.TokenMgrError: Unknown directive: #macro on line: 12, column: 101, in template: myself.ftl in myself.ftl at freemarker.template.Template.<init>(Template.java

freemarker自定义标签(与java合用)

自定义类继承FreemarkerManager类,重写protected Configuration createConfiguration(ServletContext servletContext)throws TemplateException方法定义有哪些TemplateDirectiveModel类与它的别名[自定义标签名称],通过Spring来取: import java.util.Map;import javax.servlet.ServletContext;import org.