Freemarker自定义函数的施用

Freemarker自定义函数的使用1. 编写函数???MapString,Object rootnew HashMapString, Object()root.

Freemarker自定义函数的使用

1. 编写函数

?

?

?

Map<String,Object> root=new HashMap<String, Object>();          root.put("getSysdate", new StringLengthMethod());Configuration config=new Configuration();                         File file=new File(templatePath); //并加载模板文件              config.setDirectoryForTemplateLoading(file);  //设置包装器,并将对象包装为数据模型              config.setObjectWrapper(new DefaultObjectWrapper()); //获取模板,并设置编码方式,这个编码必须要与页面中的编码格式一致              Template template=config.getTemplate(templateName,templateEncoding); //合并数据模型与模板                            template.process(root, out);

?