Jeecms原始碼分析(三)

2021-08-27 06:32:53 字數 2953 閱讀 2857

本節主要分析spring + freemarker的整合。

先介紹一下 spring+freemarker的整合主要涉及以下配置項:

1、配置 freemarkerconfigurer

……
通過 freemarkersettings

屬性,也能夠設定其他 freemarker

的配置。例如, freemarker

預設每隔 5

可以通過為 freemarkersettings

屬性設定 template_update_delay

達到這一目的。例如:

3600

設定 template_update_delay

為 3600

(秒),因此 freemarker

只有在 1

個小時之後才檢查模板是否更新。

2、解析freemarker檢視

.ftl

將請求和會話屬性作為變數暴露給 freemarker

模板使用。要做到這一點,可以設定 exposerequestattributes

或者 exposesessionattributes

為 true

true

true

使用這些巨集,必須設定 freemarkerviewresolver

的 exposemacrohelpers

屬性為 true

true

3、freemarker中繫結表單域

<@spring.bind "command.phone" />

phone: $

<@spring.bind "command.email" />

email: $

4、最後,你還需要做一件事才能使用freemarker 巨集

<#import "/spring.ftl" as spring />

這一行會在模板中匯入spring的freemarker巨集。

總體說明:

1、定義freemaker引入檔案,index.ftl字首為p,spring.ftl的字首為s,這樣在飲用ftl模版的巨集定義時,可以簡略使用。

/web-inf/ftl/pony/index.ftl as p,/web-inf/ftl/spring.ftl as s
在html表單中的使用,例如:

<@p.form id="jvform" action="o_update.do" labelwidth="12">

<@p.td

。。。。

2、在jeecms中,請求回話屬性都不允許暴露給freemarker使用。。(不知道是否跟freemarker不支援集群有關係????這樣是否可以支援集群

....

....

以下是涉及到的配置檔案:

....

contextconfiglocation

/web-inf/config/cache-context.xml

/web-inf/config/captcha-context.xml

/web-inf/config/jeecore-context.xml

/web-inf/config/jeecms-context.xml

....

在這個配置檔案中,freemarkerconfigurer作為 staticpagesvcimpl的乙個屬性,注入到這個類中。

freemarkerconfigurer的配置包括freemarker定義的標籤(見freemarkervariables),freemarkersettings中定義了一些詳細的屬性。

詳見前面的描述。

auto_detect

5utf-8

utf-8

zh_cn

true,false

yyyy-mm-dd hh:mm:ss

yyyy-mm-dd

hh:mm:ss

0.######

true

/web-inf/ftl/pony/index.ftl as p,/web-inf/ftl/spring.ftl as s

view resolver 配置:

freemarkerconfig 配置:

0utf-8

utf-8

zh_cn

true,false

yyyy-mm-dd hh:mm:ss

yyyy-mm-dd

hh:mm:ss

0.######

true

/ftl/pony/index.ftl as p,/ftl/spring.ftl as s

view resolver 配置:

freemarkerconfig 配置:引數配置與jeecms-servlet-admin.xml類似。

auto_detect

5utf-8

utf-8

zh_cn

true,false

yyyy-mm-dd hh:mm:ss

yyyy-mm-dd

hh:mm:ss

0.######

true

/web-inf/ftl/pony/index.ftl as p,/web-inf/ftl/spring.ftl as s

至此,jeecms中的freemarker的配置已經分析完畢。

redux原始碼分析(三) 原始碼部分

下面是每個部分的一些解讀 createstore apicreatestore reducer,initialstate enhancer 曾經非常好奇這個函式的第二個引數到底是initialstate還是enhancer,因為見過兩種寫法都有的,以為是版本問題。看了原始碼才發現,都可以的。如果你不...

gSOAP 原始碼分析 三

gsoap 原始碼分析 三 2012 5 25 flyfish 一 http請求方法 get 請求獲取 request uri 所標識的資源 post 在 request uri 所標識的資源後附加新的資料 head 請求獲取由 request uri 所標識的資源的響應訊息報頭 put 請求伺服器...

pomelo原始碼分析(三)

param cb callback function if this.state state inited this.loaddefaultcomponents var self this this.optcomponents start function err api private var p...