首先說說freemarker熱更新的問題。網上很多博客寫的freemarker配置熱更新用的屬性文件配置
template_update_delay=0
,但我是寫在xml裏的,不知道這個應該配置在xml裏的哪個地方。無賴之下只有翻看freemarker文檔。
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="/WEB-INF/views/"/> <property name="freemarkerSettings"> <props> <prop key="template_update_delay">0</prop> <prop key="locale">zh_CN</prop> <prop key="url_escaping_charset">UTF-8</prop> <!--<prop key="incompatible_improvements">2.3.23</prop>--> <!--<prop key="template_exception_handler">rethrow</prop>--> <prop key="default_encoding">UTF-8</prop> </props> </property> </bean>
測試一把。發現不行,好吧。繼續看文檔。
"template_update_delay"
: Template update delay in seconds (not in milliseconds) if no unit is specified; see setTemplateUpdateDelayMilliseconds(long)
for more.
String value: Valid positive integer, optionally followed by a time unit (recommended). The default unit is seconds. It's strongly recommended to specify the unit for clarity, like in "500 ms" or "30 s". Supported units are: "s" (seconds), "ms" (milliseconds), "m" (minutes), "h" (hours). The whitespace between the unit and the number is optional. Units are only supported since 2.3.23.
“template_update_delay”:如果未指定單位,模板更新延遲(以秒爲單位,而不是毫秒); 請參閱setTemplateUpdateDelayMilliseconds(long)瞭解更多。
字符串值:有效的正整數,可選後跟一個時間單位(推薦)。 默認單位爲秒。 強烈建議指定單位以便清楚,例如“500 ms”或“30 s”。 支持的單位有:“s”(秒),“ms”(毫秒),“m”(分鐘),“h”(小時)。 單位和數字之間的空格是可選的。 從2.3.23開始支持單位。
英文不佳,用軟件一點點翻譯的。
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="/WEB-INF/views/"/> <property name="freemarkerSettings"> <props> <prop key="template_update_delay">1ms</prop> <prop key="locale">zh_CN</prop> <prop key="url_escaping_charset">UTF-8</prop> <!--<prop key="incompatible_improvements">2.3.23</prop>--> <!--<prop key="template_exception_handler">rethrow</prop>--> <prop key="default_encoding">UTF-8</prop> </props> </property> </bean>
文檔寫的從2.3.23支持單位了。我就寫成1ms。再次測試。發現在還是不成功。挫敗啊。
對着電腦屏幕看了半天,突然好想明白了點什麼。在idea生成的target目錄下找到ftl模板。修改一下。刷新頁面,成功了。之前一隻都是修改的源文件,而不是tomcat上的ftl。唉,折騰了半天。記下來,希望自己以後不要在犯這樣的錯誤。