Spring MVC配置Freemarker全域性變數,實現應用全路徑
阿新 • • 發佈:2019-02-04
Xml程式碼
Xml程式碼
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程式碼
- <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="freemarkerVariables">
- <map>
- <entry key="xml_escape" value-ref="fmXmlEscape" />
- <entry key="webRoot" value="${webRoot}"></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>