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>
发布了29 篇原创文章 · 获赞 4 · 访问量 1万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章