apache freemarker中的标签以进行快速查找
我有以下代码在 Apache Freemarker 中执行过滤器(不插入重复项)。为此,我使用了一个列表,如下所示:
<#assign newList = [] />
<#list instructions as instruction>
<#if ! newList?seq_contains(instruction.opCode)>
<#assign newList = newList + [instruction.opCode] />
case ${instruction.opCode?string.computer}: instruction = create${instruction.name}(line, scope); break;
</#if>
</#list>
由于该列表实际上很大(包含几千个项目),因此需要一段时间。我想通过使用 HashSet 来加快该过程。但是,我找不到正确的方法来做到这一点。当我将列表转换为 hashMap <#assign newList = {} />
时,我无法使用 containsKey
或类似方法进行查询,而是使用 keys 进行查询
和值
。
任何指示将不胜感激。
I have the following code that performs a filter (do not insert duplicates) in Apache Freemarker. To do so, I make use of a list as follows:
<#assign newList = [] />
<#list instructions as instruction>
<#if ! newList?seq_contains(instruction.opCode)>
<#assign newList = newList + [instruction.opCode] />
case ${instruction.opCode?string.computer}: instruction = create${instruction.name}(line, scope); break;
</#if>
</#list>
Since the list is actually large (contains a few thousand items), it takes a while. I would like to speed up the process by using a HashSet instead. However, I can't find the right methods to do that. When I transform the list to a hashMap <#assign newList = {} />
then I cannot query using the containsKey
or similar methods, but rather keys
and values
.
Any pointers will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能纯粹在模板中执行此操作(具有合理的性能和可读性),因为模板语言不支持可修改的集合。你应该用Java 来进行这样的数据处理。理想情况下,数据模型(模板上下文)已经包含已处理的数据。但是,您也可以向模板公开一些 Java 实用程序,并从模板中调用这些实用程序来执行此操作。
You can't do this purely in the template (with reasonable performance and readability), as the template language doesn't support modifiable collections. You are supposed to do such data processing in Java. Ideally, the data-model (template context) already contains the data processed. But alternatively, you can expose some Java utilities to the template and call those from the template to do this.