因为商品详情页面访问量较大,为了节省带宽,提高用户体验因此我们使用freeMark技术将商品详情页静态化
1.创建Configuration对象
Configuration configuration = new Configuration();
2.设置模版存放的目录
String templateUrl = "F:/qnsport2017/parent/qnsport-console/src/main/webapp/WEB-INF/template/";
3.加载模版目录和设置读取模版的编码方式
configuration.setDirectoryForTemplateLoading(new File(templateUrl));
configuration.setDefaultEncoding("utf-8");
4.获取模版对象
Template template = configuration.getTemplate("temp.html");
5.创建数据
Map rootMap = new HashMap();
rootMap.put("name", "hello freemaker");
6.创建输出文件
Writer out = new FileWriter("C:/freemaker/demo1.html");
7.通过模版输出数据
template.process(rootMap, out);
8.关流
out.close();