FreeMarker基础学习

来源:互联网 发布:苹果4s手机的网络制式 编辑:程序博客网 时间:2024/06/01 14:39

  FreeMarker 模板技术基础语法:

1.  数据遍历:

    Map root = new HashMap();
root.put("user", "老高");   // 基本数据类型


//javabean和级联
User u = new User();
u.setUname("老马");
root.put("user1", u);
User u2 = new User("老张",new Address("中国","北京"));
root.put("user2", u2);


//map/list容器
List list = new ArrayList();
list.add(new Address("中国","北京"));
list.add(new Address("中国","上海"));
list.add(new Address("美国","纽约"));
root.put("lst", list);


//基本数据类型
root.put("num0", 18);
root.put("b2", true);
root.put("date1", new Date());
root.put("random", new Random().nextInt(100));
root.put("htm2", "<b>粗体</b>"); 

  

  数据遍历使用${}符号:   

1、你好啊,${user},${user1.uname},今天你的精神不错!
${user2.uname}来自${user2.addr.city},那里好玩吗?

2、

List数据测试:
${lst[0].city},
${lst[1].city},
${lst[2].city},

3、内建函数:
${htm2?html}


测试list指令:
<#list lst as dizhi >    <#--这里实现的是lst集合的遍历,这里和php一样 -->
 <b>dizhi</b> <br/>  

</#list>

---------------------------------------------------------

0 0
原创粉丝点击