Freemarker实现网页静态化

FreeMarker的语法

  1. 取map集合中的值${key}
  2. 取pojo类的值${student.sname}
  3. 循环<#list 集合的key as 单一变量> 取下标 单一变量_index
  4. 判断 <#if><#else>

java操作FreeMarker

    Configuration configuration=new Configuration(Configuration.getVersion());
    configuration.setDirectoryForTemplateLoading(new File(""));
    configuration.setDefaultEncoding("utf-8");
    Template template=configuration.getTemplate("test.ftl");
    Writer out=new FileWriter(new File("D:/test/test.txt"));
    Map dataModel=new HashMap<>();
    dataModel.put("hello", "hello freemarker");
    template.process(dataModel, out);

Spring整合FreeMarker

<bean id="freemarkerConfig"
    class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPath" value="/WEB-INF/ftl/" />
    <property name="defaultEncoding" value="UTF-8" />
</bean>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值