JEECMS按发布日期排序失效解决方法 - 电脑 - 【南平电脑网】_南平电脑维修_南平笔记本电脑维修_监控安装_市区上门维修
公司动态

JEECMS按发布日期排序失效解决方法

摘要:数据库中这个发布日期时间存放在两个表中,分别为jc_content和jc_content_ext这两个表中。源代码,我看一下是这样写的。以上是ContentDaoImpl类中的查询方法。加红部分为此次...

发布日期:2018-04-25
数据库中这个发布日期时间存放在两个表中,分别为jc_content和jc_content_ext这两个表中。
源代码,我看一下是这样写的。以上是ContentDaoImpl类中的查询方法。加红部分为此次生成的HQL语句。
private void appendSiteIds(Finder f, Integer[] siteIds) {
int len;
if (siteIds != null) {
len = siteIds.length;
if (len == 1) {
f.append(" and bean.site.id=:siteId");
f.setParam("siteId", siteIds[0]);
} else if (len > 1) {
f.append(" and bean.site.id in (:siteIds)");
f.setParamList("siteIds", siteIds);
}
}
}

private void appendOrder(Finder f, int orderBy) {
switch (orderBy) {
case 1:
// ID升序
f.append(" order by bean.id asc");
break;
case 2:
// 发布时间降序
f.append(" order by bean.sortDate desc");
break;
case 3:
// 发布时间升序
f.append(" order by bean.sortDate asc");
break;
case 4:
// 固顶级别降序、发布时间降序
f.append(" order by bean.topLevel desc, bean.sortDate desc");
break;
case 5:
// 固顶级别降序、发布时间升序
f.append(" order by bean.topLevel desc, bean.sortDate asc");
break;
case 6:
// 日访问降序
f.append(" order by bean.viewsDay desc, bean.id desc");
break;
case 7:
// 周访问降序
f.append(" order by bean.contentCount.viewsWeek desc");
f.append(", bean.id desc");
break;
case 8:
// 月访问降序
f.append(" order by bean.contentCount.viewsMonth desc");
f.append(", bean.id desc");
break;
case 9:
// 总访问降序
f.append(" order by bean.contentCount.views desc");
f.append(", bean.id desc");
break;
case 10:
// 日评论降序
f.append(" order by bean.commentsDay desc, bean.id desc");
break;#p#分页标题#e#
case 11:
// 周评论降序
f.append(" order by bean.contentCount.commentsWeek desc");
f.append(", bean.id desc");
break;
case 12:
// 月评论降序
f.append(" order by bean.contentCount.commentsMonth desc");
f.append(", bean.id desc");
break;
case 13:
// 总评论降序
f.append(" order by bean.contentCount.comments desc");
f.append(", bean.id desc");
break;
case 14:
// 日下载降序
f.append(" order by bean.downloadsDay desc, bean.id desc");
break;
case 15:
// 周下载降序
f.append(" order by bean.contentCount.downloadsWeek desc");
f.append(", bean.id desc");
break;
case 16:
// 月下载降序
f.append(" order by bean.contentCount.downloadsMonth desc");
f.append(", bean.id desc");
break;
case 17:
// 总下载降序
f.append(" order by bean.contentCount.downloads desc");
f.append(", bean.id desc");
break;
case 18:
// 日顶降序
f.append(" order by bean.upsDay desc, bean.id desc");
break;
case 19:
// 周顶降序
f.append(" order by bean.contentCount.upsWeek desc");
f.append(", bean.id desc");
break;
case 20:
// 月顶降序
f.append(" order by bean.contentCount.upsMonth desc");
f.append(", bean.id desc");
break;
case 21:
// 总顶降序
f.append(" order by bean.contentCount.ups desc, bean.id desc");
break;
default:
// 默认: ID降序
f.append(" order by bean.id desc");
}
}
这时就可以看到了,他前半段的HQL语句是:select bean from Content bean。这个方法是拼HQL串。
通过这个拼串后的结果,也就是select bean from Content bean order by bean.sortDate desc这查询的就是数据库表:jc_content中的sort_date字段了。
电脑互助网注:大家可以到数据库中这个表中看一下。c_content中的sort_date字段存放的都是第一次发布时间。#p#分页标题#e#

http://www.pc811.com/6/4/25788.html继上文所说,我们要查的不是第一次发布时间,而是修改时间。所以这时不合理。
所以再更新文章时,我们只需要再update时,把后台修改的发布日期时间再加入到Content的表中就可以了。JEECMS按发布日期排序失效解决方法第1步:找到Content的后台action中的update方法。进入JEECMS后台的文章更新页面,右键源代码,在源代码中搜索“.do”,直到搜索到一个o_update.do即可。

电脑互助网注:我用的是谷歌浏览器,在谷歌浏览器中查看提交按扭的表单,发现表单就是提交到o_update.do的。

第2步:我们都知道com.jeecms.cms.action.admin.main这个包是所有后台操作action包类。所以就要到这个下面去找。
另,我们还知道,我们操作是的Content类,所以只有一个类了,就是:ContentAct。双击打开此类。


第3步:通过ContentAct中搜索“o_update.do”,找到public String update(.......参数很多...)方法。并在此方法中找到以下代码。
bean = manager.update(bean, ext, txt, tagArr, channelIds, topicIds, viewGroupIds, attachmentPaths, attachmentNames, attachmentFilenames, picPaths, picDescs, attr, channelId, typeId, draft, user, false);

第4步:通过以上这些代码,锁定到接口ContentMng下的update。并再次通过ContentMng接口找到它的实现类ContentMngImpl。
并在ContentMngImpl中找到update方法。

在Content entity = findById(bean.getId());下面加入
bean.setSortDate(new Timestamp(System.currentTimeMillis()));//这个是直接加载当前系统日期时间
bean.setSortDate(ext.getReleaseDate()); //如果使用这个就是取后台发布时间设置的时间。
我个人推荐使用第二个。
电脑互助网注:Content entity = findById(bean.getId());使用ID查询单个实体信息。
把当前系统日期加入到Content实体中。

第4步:完成以上步骤,就已经完成了。再次修改文章信息时,就可以把文章发布时间给同步到文章信息表中了。而不会再出现一个Content信息表发布时间有两修水同的时间了。