本文内容:
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">

本文详细介绍了如何在SpringMVC中整合Freemarker以创建自定义标签,包括必要的jar包依赖、Spring配置以及实现TemplateDirectiveModel接口的方法。通过这些步骤,可以在页面上自由使用自定义标签。同时,文章深入探讨了TemplateDirectiveModel接口,特别是其execute方法的用法。
最低0.47元/天 解锁文章
734

被折叠的 条评论
为什么被折叠?



