1.Freemark 自定义宏(也就是自定义标签)
<@p.form id="jvForm" tableClass="table table-hover table-striped table-bordered vtable" action="directive/o_save.do" labelWidth="30">
<@p.td required="true" label='directive.module' colspan='2' width="100">
<@p.select onchange="selectModule()" />
</@p.td>
</@p.form>
这段html
把我吓了一跳,什么玩意
解释一下:
p:是在freemarkerConfig中配置的一个 别名
<prop key="auto_import">/WEB-INF/ftl/index.ftl as p,/WEB-INF/ftl/spring.ftl as s</prop>
form/td/select:都是自定义的 <#macro 标签,在index.ftl中都已经定义好了
spring.ftl 中的
<#macro m code>${springMacroRequestContext.getMessage(code)}</#macro>
springMacroRequestContext:这个东西是固定的 在 org.springframework.web.servlet.view.AbstractTemplateView 中定义好的
2.Freemark 标签类型<>,[]
配置文件中设置 tag_syntax 属性可以控制标签类型
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="freemarkerSettings">
<props>
<!-- 设置标签类型 auto_detect(自动检测第一次出现的标签类型)、angle_bracket(<>)、square_bracket([])-->
<prop key="tag_syntax">auto_detect</prop>
<prop key="template_update_delay">5</prop>
<prop key="defaultEncoding">UTF-8</prop>
<prop key="url_escaping_charset">UTF-8</prop>
<prop key="locale">zh_CN</prop>
<prop key="boolean_format">true,false</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="date_format">yyyy-MM-dd</prop>
<prop key="time_format">HH:mm:ss</prop>
<prop key="number_format">0.######</prop>
<prop key="whitespace_stripping">true</prop>
<!--空值处理<prop key="classic_compatible">true</prop>-->
<prop key="auto_import">/WEB-INF/ftl/doccms/index.ftl as p,/WEB-INF/ftl/spring.ftl as s</prop>
</props>
</property>
</bean>