0

I am new to apache velocity, I want to create a subList Object from the List Objects which are coming from some service call in .vm file.

We need to render the list based on some logic in parts, for that we want to create sublist from list.

$table.getBooks() //contains all the Books objects Below is the sample code which I tried but it did not work.

#set($segregatedList = [])
#set($size = $table.getLineItems().size())
#foreach($index in [0..$size-1])
#set($value = $index + 4)
#set($minimum = $math.min($nItems,$value))
$segregatedList.add($table.getBooks().subList($index,$minimum)))
$index += 4
#end

I executed the code, while rendering $segregatedList is coming as null. I verified $table.getBooks() contains the Objects as when I am passing this,Objects are getting rendered successfully. Can someone please tell what I am doing wrong or how can I create a sublist ?


Cloning ec2 linux instance on aws in local environment

I have a production server running on AWS ec2 instance. Since I was a beginner when I started everything I hadn't use virtual env etc.

Now, there are many dependencies and packages that I have installed somehow. Is there a way to clone entire AWS ec2 instance environment with all the packages into my local machine for dev work. I know from pip freeze I can get all the python dependencies (I have a running Django server). But is there a way to clone everything (from docker etc.).

4

1 回答 1

0

首先,您将索引增加 4 并可能导致 IndexOutOfBoundsException,因此需要更改直到size-5(因此删除数学最小值检查)

其次,您使用addAll添加单个元素而不是所有元素

第三,您的尺寸检查是否有错误的参数 - 应该是相关的$table.getBooks()

最后确保你的列表有超过 5 个元素

#set($segregatedList = [])
#set($size = $table.getBooks().size())
#foreach($index in [0..$size-5])
#set($value = $index + 4)    
$segregatedList.addAll($table.getBooks().subList($index, $value)))
$index += 4
#end
于 2017-10-15T08:25:15.513 回答