Spring MVC配置Freemarker全局变量,实现应用全路径

    xiaoxiao2021-03-25  54

    Xml代码   <context:property-placeholder location="classpath:config.properties" ignore-unresolvable="true"/>   <context:property-placeholder location="classpath:config.properties" ignore-unresolvable="true"/> Xml代码   <bean id="freemarkerConfiguration"          class="org.springframework.beans.factory.config.PropertiesFactoryBean">          <property name="location" value="classpath:freemarker.properties" />      </bean>        <!-- 配置freeMarker的模板路径 -->      <bean id="freemarkerConfig"          class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">          <property name="freemarkerSettings" ref="freemarkerConfiguration"></property>          <property name="templateLoaderPath" value="/WEB-INF/view/"/>          <property name="freemarkerVariables">              <map>                  <entry key="xml_escape" value-ref="fmXmlEscape" />                  <entry key="webRoot" value="${webRoot}"></entry>                  <entry key="jsRoot" value="${jsRoot}"></entry>              </map>          </property>      </bean>        <bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape" />   <bean id="freemarkerConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="location" value="classpath:freemarker.properties" /> </bean> <!-- 配置freeMarker的模板路径 --> <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="freemarkerSettings" ref="freemarkerConfiguration"></property> <property name="templateLoaderPath" value="/WEB-INF/view/"/> <property name="freemarkerVariables"> <map> <entry key="xml_escape" value-ref="fmXmlEscape" /> <entry key="webRoot" value="${webRoot}"></entry> <entry key="jsRoot" value="${jsRoot}"></entry> </map> </property> </bean> <bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape" /> config.properties文件: jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc\:mysql\://127.0.0.1\:3306/test?useUnicode\=true&characterEncoding\=utf8 jdbc.username=root jdbc.password=root webRoot=http\://127.0.0.1\:8080/freemarker/ jsRoot=${webRoot}resources/ freemarker.properties文件 tag_syntax=auto_detect template_update_delay=60 default_encoding=UTF-8 output_encoding=UTF-8 locale=zh_CN date_format=yyyy-MM-dd time_format=HH:mm:ss datetime_format=yyyy-MM-dd HH:mm:ss ftl页面引用全局变量: Html代码   <script type="text/javascript" src="${jsRoot}jquery-1.4.2.min.js"></script>   <script type="text/javascript" src="${jsRoot}jquery-1.4.2.min.js"></script>
    转载请注明原文地址: https://ju.6miu.com/read-34777.html

    最新回复(0)