以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等注意注解的问题。 
    
  


 
					 
					