Liferay中查詢最新版本的文章列表

因爲在官方API中沒有找到相似的方式,可使用Liferay的動態query進行查詢。java

示例:app

//OrderByComparator obc = new ArticleModifiedDateComparator(false);
//articleList = JournalArticleLocalServiceUtil.getArticles(groupId, folderId, start, end, obc);

DynamicQuery maxVersionArticle = DynamicQueryFactoryUtil
		.forClass(JournalArticle.class, "maxVersionArticle", PortalClassLoaderUtil.getClassLoader())
		.add(PropertyFactoryUtil.forName("articleId").eqProperty("articleByType.articleId"))
		.setProjection(ProjectionFactoryUtil.max("id"));

// articleByType : Query will find the articles by its type and
// appended the maxVersionArticle query so it will track only latest versions

DynamicQuery articleByType = DynamicQueryFactoryUtil
		.forClass(JournalArticle.class, "articleByType", PortalClassLoaderUtil.getClassLoader())
		.add(PropertyFactoryUtil.forName("id").eq(maxVersionArticle))
		.add(PropertyFactoryUtil.forName("folderId").eq(folderId))
		.add(PropertyFactoryUtil.forName("groupId").eq(groupId))
		.addOrder(OrderFactoryUtil.desc("modifiedDate"));
相關文章
相關標籤/搜索