JEECMS站群管理系统-- 标签的配置流程

摘要:
在cms_content_例如,列表。首先,在jeecms上下文中声明每个标签。此外,在配置文件jeecmservletfront中。xml中,有一部分标记配置…class ContentListDirective继承自AbstractContentDirective,最重要的是执行方法publicclassContentListDirectiveextendsAbstractContentDirective{/***模板名称*/publicstaticfinalStringTPL_name=“content_list”;/***输入参数,文章ID。允许多个文章ID,用“,”分隔。排除所有其他筛选参数。

以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"  />(声明标签对应的类)
<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 cms_sys_definedstyle_liststyle_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="http://t.zoukankan.com/${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等注意注解的问题。

免责声明:文章转载自《JEECMS站群管理系统-- 标签的配置流程》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇javascript 未来新方法的介绍初识依赖注入(DI)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

MyCat 学习笔记 第十二篇.数据分片 之 分片事务处理

1 环境说明 VM 模拟3台MYSQL 5.6 服务器    VM1 192.168.31.187:3307    VM2 192.168.31.212:3307    VM3 192.168.31.150:  3307 MYCAT 1.5 服务部署在宿主机上   MYCAT 192.168.31.207 :8806【SQL执行端口】 / 9066【管理端...

XML常用标签的介绍

1、引言   在使用Java时经常遇到使用XML的情况,而因为对XML不太了解,经常配置时粘贴复制,现在对它进行总结,以备以后使用。 2、XML常见的定义  (1)XML(Extensible Markup Language):即可扩展标记语言,它的特性如下: 可扩展标记语言是一种很像超文本标记语言的标记语言。 它的设计宗旨是传输数据,而不是显示数据。...

spring-装配bean

1.spring配置的可选方案 spring提供了三种装配bean的机制: 在xml中显式配置 在java中进行显式配置 隐式的bean发现机制和自动转配 三种方式在适当的场合使用,当然你可以选择自己喜欢的方式转配bean。 2.自动化装配bean spring从两个角度实现自动化装配 组件扫描(component scanning)spring会自...

MyCat 概念与配置

1.1 Mycat 介绍与核心概念 1.1.1 基本介绍 历史:从阿里 cobar 升级而来,由开源组织维护,2.0 正在开发中。 定位:运行在应用和数据库之间,可以当做一个 MySQL 服务器使用,实现对 MySQL数据库的分库分表,也可以通过 JDBC 支持其他的数据库。 Mycat 的关键特性(官网首页) 1、可以当做一个 MySQL 数据库来...

EJB3 阶段总结+一个EJB3案例 (2)

这篇博文接着上一篇博文的EJB案例。 在上一篇博文中,将程序的架构基本给描述出来了,EJB模块分为5层。 1)DB层,即数据库层     在则一部分,我使用的数据库为mysql。在EJB程序中,访问数据库是通过Jboss中配置好的数据源进行的,然后在数据库中建立相应的数据库,不用建立表,在程序中使用JPA后通过Jboss启动会自动在数据库中间表     具...

彻底搞懂Spring类加载(注解方式)

单例预加载默认 单例懒加载   正确的加载时机   错误的加载时机 多例懒加载仅支持懒加载 spring beanfactory类高级用法   反射方式加载类 需要注意的问题 通过 Spring 注册的类一共只有三种加载方式! 环境:spring-context 4.2.6jdk 8Eclipse 4.7 最简单的配置 <?xml ve...