Liferay-如何从velocity模板增加资源的视图计数

Liferay-如何从velocity模板增加资源的视图计数,liferay,velocity,assets,Liferay,Velocity,Assets,是否可以从velocity模板以编程方式增加资产条目的视图计数 谢谢您的回答。这应该是可能的,毕竟它只是更新liferay实体 如果可以获得AssetEntryService,则可以调用将视图计数器增加1的方法incrementViewCounter 因此,在您的模板中,您将有如下代码: #set ($assetEntryService = $serviceLocator.findService('com.liferay.portlet.asset.service.AssetEntryServi

是否可以从velocity模板以编程方式增加资产条目的视图计数


谢谢您的回答。

这应该是可能的,毕竟它只是更新liferay实体

如果可以获得
AssetEntryService
,则可以调用将视图计数器增加1的方法
incrementViewCounter

因此,在您的模板中,您将有如下代码:

#set ($assetEntryService = $serviceLocator.findService('com.liferay.portlet.asset.service.AssetEntryService'))
$assetEntryService.incrementViewCounter(String className, long classPK)
如果要指定增量值而不是默认值1,则需要
AssetEntryLocalService
的实例,如下所示:

#set ($assetEntryLocalService = $serviceLocator.findService('com.liferay.portlet.asset.service.AssetEntryLocalService'))
$assetEntryService.incrementViewCounter(long userId, String className, long classPK, long increment)
increment
=将当前的
viewCount
增加此值


我希望我已经理解了要求。

谢谢。你是对的,除了一件事:方法incrementViewCounter需要参数String className和long classPK。在我的示例中,我不得不使用“com.liferay.portlet.journal.model.JournalArticle”作为类名。在这之后,增量工作正常。请用正确的论据编辑你的答案,我会接受的。再次感谢,谢谢你指出这一点。这就是我执行多任务时发生的情况:)