专注JavaWeb开发 首页制式『默认式 OR 时间轴 网站地图|RSS订阅|设为首页|加入收藏
当前位置:首页 >Java >JavaEE中级 > 正文

freemarker 直接使用List来遍历set集合,可能会报错

作者: admin 发布时间: 2015-04-08 浏览次数:

freemarker  直接使用List来遍历set集合,可能会报错! 错误如下

Java代码

private Set<Article> articles = new HashSet<Article>();

Freemarker中遍历

[#list category.articles?chunk(5) as article1]
     <div>
         <ul>
              [#list article1 as article ]
                [#assign articleDesc=i18n_description(article.articleDescriptions,true)/]
                [#if articleDesc!=null]
         ${abbreviate(articleDesc.title, 80, "...")}
         [/#if]
            [/#list]
          </ul>
      </div>
 [/#list]

 报错信息

Underlying collection is not a list, it's org.hibernate.collection.internal.PersistentSet

freemarker.template.TemplateModelException: Underlying collection is not a list, it's org.hibernate.collection.internal.PersistentSet

         at freemarker.ext.beans.CollectionModel.get(CollectionModel.java:127)

         at freemarker.core.SequenceBuiltins$chunkBI$ChunkedSequence$1.get(SequenceBuiltins.java:792)

         at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:176)

         at freemarker.core.Environment.visit(Environment.java:428)

         at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)

         at freemarker.core.Environment.visit(Environment.java:221)

         at freemarker.core.MixedContent.accept(MixedContent.java:92)

         at freemarker.core.Environment.visit(Environment.java:221)

         at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)

         at freemarker.core.Environment.visit(Environment.java:428)

         at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)

         at freemarker.core.Environment.visit(Environment.java:221)

         at freemarker.core.MixedContent.accept(MixedContent.java:92)

         at freemarker.core.Environment.visit(Environment.java:221)

         at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)

         at freemarker.core.Environment.visit(Environment.java:221)

         at freemarker.core.MixedContent.accept(MixedContent.java:92)

         at freemarker.core.Environment.visit(Environment.java:221)

         at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)

         at freemarker.core.Environment.visit(Environment.java:221)

         at freemarker.core.MixedContent.accept(MixedContent.java:92)

         at freemarker.core.Environment.visit(Environment.java:221)

         at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)

         at freemarker.core.Environment.visit(Environment.java:428)

         at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)

         at freemarker.core.Environment.visit(Environment.java:221)

         at freemarker.core.Environment$1.render(Environment.java:246)

         at com.eecart.template.directive.BaseDirective.setLocalVariable(BaseDirective.java:184)

         at com.eecart.template.directive.ArticleCategoryRootListDirective.execute(ArticleCategoryRootListDirective.java:51)

         at freemarker.core.Environment.visit(Environment.java:274)

         at freemarker.core.UnifiedCall.accept(UnifiedCall.java:126)

         at freemarker.core.Environment.visit(Environment.java:221)

解决方案:

不直接使用 articles

@Transient

   public List<Article> getMyArticles(){

      List<Article> list = new ArrayList<Article>(articles);

      return list;

   }


QQ群: 武汉地区(142173356)验证消息JavaWeb1024

网友共有【】评论,点击查看



x 微信关注我们 随时获取最新网站资讯