查看JEECMS的源代码发现开发者版本还没有类似现成的统计标签,一种解决的办法是使用现有的JEECMS标签,像这样Struts( [@cms_content_list channel=id]${tag_list?size}[/@cms_content_list]) ,但是这样的做法非常地低效,原因是[@cms_content_list]标签会把所有当前栏目的文章内容对象查询出来,做全表查询!
为了网站访问效率,只好自己写一个统计标签[@cms_channel_statistic]为例说下如何在JEECMS加入自定义标签。
第一步:编写装载统计信息的Entity。
/**
* 频道统计实体类
* @author www.javake.net
*/
public class ChannelStatistics {
/**
* 文章总数
*/
private long contentAllCount;
/**
* 待审核文章总数
*/
private long contentCheckingCount;
/**
* 评论总数
*/
private long commentCount;
/**
* 阅读总数
*/
private long viewCount;
public long getContentAllCount() {
return contentAllCount;
}
public void setContentAllCount(long contentAllCount) {
this.contentAllCount = contentAllCount;
}
public long getContentCheckingCount() {
return contentCheckingCount;
}
public void setContentCheckingCount(long contentCheckingCount) {
this.contentCheckingCount = contentCheckingCount;
}
public long getCommentCount() {
return commentCount;
}
public void setCommentCount(long commentCount) {
this.commentCount = commentCount;
}
public long getViewCount() {
return viewCount;
}
public void setViewCount(long viewCount) {
this.viewCount = viewCount;
}
}
第二步:编写栏目信息统计的Dao接口。暂时只实现文章总数统计,待审核文章统计,评论总数 cop
/**
* 栏目信息统计Dao接口
* @author www.javake.net
*/
public interface CmsChannelStatisticDao {
/**
* 当前栏目文章统计
* @param restrictions
* @return
*/
public long contentStatistic(Map<String, Object> restrictions);
/**
* 当前栏目待审核文章统计
* @param restrictions
* @return
*/
public long contentCheckingStatistic(Map<String, Object> restrictions);
/**
* 当前栏目评论统计
* @param restrictions
* @return
*/
public long commentStatistic(Map<String, Object> restrictions);
}
第三步:编写Dao接口的实现。