本文内容:
1. 基于SpringMVC整合Freemarker的自定义标签实例。
2. TemplateDirectiveModle 的详解
3. 自定义标签使用的小技巧
一、基于SpringMVC整合Freemarker的自定义标签实例
1、jar包依赖,配置到项目pom.xml
<!-- Freemarker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
<!-- 还有一些列的SpringMVC 包不列出了,核心的就是上面的freemarker jar -->
2、Spring 的配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- 存放freemarker自定义标签实现类的包-->
<context:component-scan base-package="org.oc.freemarker.directives"></context:component-scan>
<bean id="freemarkerConfig"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<!-- 视图解析器会在/WEB-INF/ftl/路径下扫描ftl文件 -->
<property name="templateLoaderPath" value="/WEB-INF/template/" />
<property name="freemarkerSettings"