关于freemaker页面静态化的使用

Freemarker静态化页面实践
本文介绍如何利用Freemarker技术实现商品详情页的静态化处理,通过具体步骤展示了配置模版、加载数据并输出静态文件的过程。

因为商品详情页面访问量较大,为了节省带宽,提高用户体验因此我们使用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();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值