以cms_content_list為例,首先,每一個標簽的聲明都是在jeecms-context.xml中進行的,
<?xml?version="1.0"?encoding="UTF-8"?>
<beans?xmlns="http://www.springframework.org/schema/beans"?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans?http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
default-lazy-init="true">
……
<bean?id="cms_content_list"?class="com.jeecms.cms.action.directive.ContentListDirective"/>(聲明標簽對應的類)
<bean?id="staticPageSvc"?class="com.jeecms.cms.staticpage.StaticPageSvcImpl">
<property?name="freeMarkerConfigurer">
<bean?class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property?name="freemarkerVariables">
<map>
……
<entry?key="cms_content_list"?value-ref="cms_content_list"/>
……
</map>
</property>
<property?name="templateLoaderPath"?value=""/>
……
</bean>
</property>
</bean>
</beans>
此外,在配置文件jeecms-servlet-front.xml中,還有一段對標簽的配置
<bean?id="freemarkerConfig"?class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property?name="freemarkerVariables">
<map>
……
<entry?key="cms_content_list"?value-ref="cms_content_list"/>
……
?? </map>
</property>
?????????……
</bean>
</bean>類ContentListDirective繼承自AbstractContentDirective,最主要的是execute方法
public?class?ContentListDirective?extends?AbstractContentDirective?{
/**
?*?模板名稱
?*/
public?static?final?String?TPL_NAME?=?"content_list";
/**
?*?輸入參數,文章ID。允許多個文章ID,用","分開。排斥其他所有篩選參數。
?*/
public?static?final?String?PARAM_IDS?=?"ids";
@SuppressWarnings("unchecked")
public?void?execute(Environment?env,?Map?params,?TemplateModel[]?loopVars,
TemplateDirectiveBody?body)?throws?TemplateException,?IOException?{
//獲取站點
CmsSite?site?=?FrontUtils.getSite(env);
//獲取內容列表,可以通過此處進行更改,獲取自己數據庫中的數據
List<Content>?list?=?getList(params,?env);
Map<String,?TemplateModel>?paramWrap?=?new?HashMap<String,?TemplateModel>(
params);
//OUT_LIST值為tag_list,在類DirectiveUtils中聲明,將內容列表放入其中
paramWrap.put(OUT_LIST,?DEFAULT_WRAPPER.wrap(list));
//將params的值復制到variable中
Map<String,?TemplateModel>?origMap?=?DirectiveUtils
.addParamsToVariable(env,?paramWrap);
//獲取的是參數PARAM_TPL,是否調用模板以及調用的模板類型
InvokeType?type?=?DirectiveUtils.getInvokeType(params);
//獲取傳入參數,列表樣式,根據不同的參數獲取不同的樣式列表
String?listStyle?=?DirectiveUtils.getString(PARAM_STYLE_LIST,?params);
if?(InvokeType.sysDefined?==?type)?{
if?(StringUtils.isBlank(listStyle))?{
throw?new?ParamsRequiredException(PARAM_STYLE_LIST);
}
//列表樣式模板
env.include(TPL_STYLE_LIST?+?listStyle?+?TPL_SUFFIX,?UTF8,?true);
}?else?if?(InvokeType.userDefined?==?type)?{
if?(StringUtils.isBlank(listStyle))?{
throw?new?ParamsRequiredException(PARAM_STYLE_LIST);
}
//列表樣式模板路徑?WEB-INF\t\cms_sys_defined\style_list\style_2-1.html
FrontUtils.includeTpl(TPL_STYLE_LIST,?site,?env);
}?else?if?(InvokeType.custom?==?type)?{
//這個模板就是自己聲明的,即content_list.html,如果采用自定義模板的話,頁面中可以只寫上標簽,并添加上標簽內需要的幾個參數,不需要寫標簽體的內容,會去自動調用模板中的標簽體。
FrontUtils.includeTpl(TPL_NAME,?site,?params,?env);
}?else?if?(InvokeType.body?==?type)?{
body.render(env.getOut());
}?else?{
throw?new?RuntimeException("invoke?type?not?handled:?"?+?type);
}
//將variable中的params值移除
DirectiveUtils.removeParamsFromVariable(env,?paramWrap,?origMap);
}
@SuppressWarnings("unchecked")
protected?List<Content>?getList(Map<String,?TemplateModel>?params,
Environment?env)?throws?TemplateException?{
Integer[]?ids?=?DirectiveUtils.getIntArray(PARAM_IDS,?params);
if?(ids?!=?null)?{
//根據內容ID數組獲取文章列表
return?contentMng.getListByIdsForTag(ids,?getOrderBy(params));
}?else?{
return?(List<Content>)?super.getData(params,?env);
}
}
@Override
protected?boolean?isPage()?{
return?false;
}
}
Content_list.html中的內容
[#list?tag_list?as?a]
<li><a?href="${a.url}"?target="_blank">${a.title}</a></li>
[/#list]
就是簡單的將tag_list中的內容,即“paramWrap.put(OUT_LIST,?DEFAULT_WRAPPER.wrap(list));”中放入的數據遍歷出來
style_2-1.html中的內容?主要是對圖文列表或標題列表向上滾動的樣式的,其中包含兩個同樣為樣式的文件
style_2-1_core.html(圖文列表或標題列表向上滾動)和style_1-1_core.html(圖文列表或標題列表向上滾動),在此就不做贅述了。
Jeecms是基于Spring注解,在自定義標簽時對于實體類和dao?service等注意注解的問題。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
