freemarker自定义标签

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

本文内容:
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"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值