使用Velocity中的数组参数调用java方法

时间:2012-03-31 20:37:32

标签: java arrays methods liferay velocity

我正在编写一个速度模板文件(.vm),我在其中使用反射:

#set ($assetEntryQuery = $portal.getClass().forName("com.liferay.portlet.asset.service.persistence.AssetEntryQuery").getConstructor().newInstance())

然后我创建一个数组并调用此函数:

#set ($arr = ['$category.getCategoryId()'])
$assetEntryQuery.setStart(0)
$assetEntryQuery.setEnd(6)
$assetEntryQuery.setAllCategoryIds($arr)

不幸的是,setAllCategoryIds接受数组long [],而不是Velocity数组。我在网站上得到的是“$ assetEntryQuery.setAllCategoryIds($ arr)”正在打印。你们有谁知道如何让它发挥作用?

1 个答案:

答案 0 :(得分:0)

您应该删除['$ category.getCategoryId()']周围的单引号,以便:[$ category.getCategoryId()]

EDIT 作为一个黑客和解决方法,这解决了这个问题:

$assetEntryQuery.setAllCategoryIds($category.getCategoryId())

因为velocity支持方法中的varargs(参见本答案中的注释)。

相关问题