freemarker自定义标签(二十一)
一,讲解一
1、自定义标签说明
宏变量存储模板片段可以被用作自定义指令macro
2、示例说明
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>freemarker自定义标签</title>
</head>
<body>
<#--freemarker自定义标签-->
<#macro write>
repeat("张三丰",3)
</#macro>
<@write/>
</body>
</html>
3、示例结果
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>freemarker自定义标签</title>
</head>
<body>
repeat("张三丰",3)
</body>
</html>
二,讲解二
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>
三,讲解三nested指令
1、nested指令
是可选的,可以在<#macro>和</#macro>之间使用在任何位置和任意次数
2、示例说明
<#macro tag>
<#nested/>
</#macro>
<@tag>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</@tag>
3、运行结果
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
freemarker自定义标签(二十一)的更多相关文章
- freemarker自定义标签报错(二)
freemarker自定义标签 1.错误描述 freemarker.core.ParseException: Unexpected end of file reached. at freemarker ...
- freemarker自定义标签(二)
freemarker自定义标签 1.自定义标签 通过自定义标签,写一个重复指定字符串 2.实现源码 <html> <head> <meta http-equiv=&quo ...
- OneBlog开源博客-详细介绍如何实现freemarker自定义标签
前言 OneBlog中使用到了springboot + freemarker的技术,同时项目里多个controller中都需要查询一个公有的数据集合,一般做法是直接在每个controller的方法中通 ...
- freemarker自定义标签报错(六)
freemarker自定义标签 1.错误描述 freemarker.core.ParseException: Encountered "\"\u4f60\u597d\uff01\& ...
- freemarker自定义标签报错(五)
freemarker自定义标签 1.错误描述 六月 05, 2014 11:40:49 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严 ...
- freemarker自定义标签报错(四)
freemarker自定义标签 1.错误描述 六月 05, 2014 11:31:35 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严 ...
- freemarker自定义标签(一)
freemarker自定义标签 1.自定义标签说明 宏变量存储模板片段可以被用作自定义指令macro 2.示例说明 <html> <head> <meta http-eq ...
- freemarker自定义标签报错(三)
freemarker自定义标签 1.错误描述 freemarker.core.ParseException: Encountered " " at line 14, column ...
- freemarker自定义标签报错(一)
freemarker自定义标签 1.错误描述 freemarker.core.ParseException: Token manager error: freemarker.core.TokenMgr ...
随机推荐
- (python基础)时间辍time、时间元组localtime、时间格式化strftime
可以直接将下方代码运行查看结果:#!/usr/bin/python# coding=utf-8import time # 引入time模块# 时间戳:# 每个时间戳都以自从1970年1月1日午夜(历元 ...
- Flask 开发| Flaskr 开发内容总结
Flaskr 开发说明 官方文档 http://flask.pocoo.org/docs/0.12/tutorial/ 演示网站 http://flaskr.it592.com/ 涉及到的内容: 连接 ...
- Python数据结构之三——dict(字典)
Python版本:3.6.2 操作系统:Windows 作者:SmallWZQ 知识源于生活.Python也是如此. 提到字典,我首先想到的是数学大师--高斯. 为何想起他呢?这主要是因为高斯算法 ...
- S5PV210时钟,看门狗定时器
晶振:时钟源(操作主要有两个,倍频,分频) A8的时钟源: 时钟域,每个时钟域(不同的最高频率和最低频率)管理着不同的电路模块: 不同的时钟域对应不同电路模块表 时钟电路:懂得看时钟电路(时钟源选择开 ...
- 获取对象属性类型、属性名称、属性值的研究:反射和JEXL解析引擎
同步发布:http://www.yuanrengu.com/index.php/20170511.html 先简单介绍下反射的概念:java反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所 ...
- Conemu, Msys2 工具整合,提升windows下控制台工作效率
与windows cmd相比较git-bash这类的console工具好用很多,但是git-bash的命令和功能相对简单,功能扩展起来不方便,git-bash本身也是基于msys的. 昨天发现使用Ms ...
- java中的Collection集合类
随着1998年JDK 1.2的发布,同时新增了常用的Collections集合类,包含了Collection和Map接口.而Dictionary类是在1996年JDK 1.0发布时就已经有了.它们都可 ...
- 百度前端技术学院js任务三
任务地址:http://ife.baidu.com/course/detail/id/98 代码: <!DOCTYPE> <html> <head> <met ...
- wss 协议传送过来的数据是经过 gzip 压缩过的,如何使用 qt 解压该数据呢?
#include <QtZlib/zlib.h> QByteArray qGzipUncompress(const QByteArray& data) { if (!data.da ...
- ActiveMq笔记1-消息可靠性理论
原博客:http://shift-alt-ctrl.iteye.com/blog/2020182 https://mp.weixin.qq.com/s/h74d6LtGB5M8VF0oLrXdCA 我 ...