freemarker API 之 Configuration介绍

来源:互联网 发布:淘宝女装店铺名字 编辑:程序博客网 时间:2024/05/17 06:57

摘自:http://hi.baidu.com/gzdx968342/blog/item/08bcd856f666854e1038c2c4.html

freemarker.template.Configuration

1..setDefaultEncoding(encoding) //设置缺省编码方式。比如,defaultEncode=UTF-8

2.setSharedVariable(String name, TemplateModel tm)//设置共享变量,使得java API 能在ftl文件中使用,比如,

org.apache.commons.lang.StringUtils

org.apache.commons.lang.ObjectUtils

org.apache.commons.collections.CollectionUtils

还可以导入自己的工具类等。。。

3.setSettings(Properties props) 设置一些属性,比如缓存策略

Configuration.CACHE_STORAGE_KEY=“cache_storage”

cache_storage=strong:20, soft:250

MRU Cache(Most Recently Used最近最经常使用)
双缓存,strong:20 强引用不会被从虚拟机中回收,软引用soft:250则会,当强引用满了后,会把极少用到的部分移到软引用(二级缓存)中

FreeMarker template 能在cache中缓存起来,只要创建一次就可以了
Could not find template in cache, creating new one;
Compiling FreeMarker template

4.setTemplateLoader(TemplateLoader loader)//设置模板路径

比如 "/" 代表classpath根路径

原创粉丝点击