qq_35770741
冲天猴Corbett
2018-01-24 16:17
采纳率: 33.3%
浏览 1.8k

freemarker生成模板在windows下正常运行而在linux下报错数组越界

我需要使用freemarker生成html文件,在windows系统下能够正常运行,但是在linux系统下报错数组越界。

下面是代码:

    public boolean generateHotArticleFreeMarker(PageData pd) throws Exception {
        Configuration configuration = freeMarkerConfigurer.getConfiguration();
        Template template = configuration.getTemplate("hotarticle.ftl");
        PageData map = new PageData();

        Result result = hotArticleService.getHotArticleList(pd);
        map.put("totalPage", result.getTotalPage());
        map.put("currentPage", result.getCurrentPage());
        map.put("rows", result.getRows().size() > 0 ? result.getRows() : "");

        List<TbCategory> categoryList = categoryService.getCategoryList();
        map.put("categoryList", categoryList);

        map.put("resultPd", pd);
        FileWriter out = new FileWriter(new File(FREEMARKER_PATH + pd.getString("id") + ".html"));
        template.process(map, out);

        out.close();
        return true;
    }

在执行到template.process(map, out);这一行时候报错:

 java.lang.ArrayIndexOutOfBoundsException: 415315061
    at java.util.HashMap.putForCreate(HashMap.java:541)
    at java.util.HashMap.putAllForCreate(HashMap.java:555)
    at java.util.HashMap.clone(HashMap.java:796)
    at freemarker.template.SimpleHash.copyMap(SimpleHash.java:153)
    at freemarker.template.SimpleHash.<init>(SimpleHash.java:133)
    at freemarker.template.DefaultObjectWrapper.wrap(DefaultObjectWrapper.java:230)
    at freemarker.template.Template.createProcessingEnvironment(Template.java:475)
    at freemarker.template.Template.process(Template.java:382)
    at com.goodlymoon.portal.service.freemarker.HtmlFreeMarker.generateHotArticleFreeMarker(HtmlFreeMarker.java:94)
    at com.goodlymoon.portal.service.impl.HotArticleServiceImpl.saveHotArticle(HotArticleServiceImpl.java:98)
    at com.goodlymoon.portal.service.impl.HotArticleServiceImpl.getWinXinHotArticle(HotArticleServiceImpl.java:155)
    at com.goodlymoon.portal.service.impl.HotArticleServiceImpl$$FastClassBySpringCGLIB$$19625a23.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
    at com.goodlymoon.portal.service.impl.HotArticleServiceImpl$$EnhancerBySpringCGLIB$$7c74333.getWinXinHotArticle(<generated>)
    at com.goodlymoon.portal.service.timer.QuartzTask$HotArticleTask.run(QuartzTask.java:97)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

有没有大神帮忙看看有什么好的解决办法吗?

我觉得路径是没有问题的,因为在指定的文件夹下生成了文件,只是没有写入内容,附图片
图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

10条回答 默认 最新

  • fsp357838
    fsp357838 2018-01-24 16:29
    已采纳

    你确定在两个系统上是对同样的文件使用freemarker?

    点赞 评论
  • devmiao
    devmiao 2018-01-24 16:31

    看下FileWriter out = new FileWriter(new File(FREEMARKER_PATH + pd.getString("id") + ".html"));
    这个里面的路径

    点赞 评论
  • srddrs
    srddrs 2018-01-24 16:36

    路径错了。注意文件分隔符不一样

    点赞 评论
  • u013026750
    老果子 2018-01-24 22:43

    需要查看freemarker中对数值的处理

    点赞 评论
  • qq_32692255
    qq_32692255 2018-01-25 00:32

    看下FileWriter out = new FileWriter(new File(FREEMARKER_PATH + pd.getString("id") + ".html"));
    这个里面的路径, 需要查看freemarker中对数值的处理

    点赞 评论
  • qq_35621581
    qq_35621581 2018-01-25 01:56

    看下FileWriter out = new FileWriter(new File(FREEMARKER_PATH + pd.getString("id") + ".html"));
    这个里面的路径, 需要查看freemarker中对数值的处理

    点赞 评论
  • qq_35621581
    qq_35621581 2018-01-25 01:57

    FileWriter outs = new FileWriter(new File(FREEMARKER_PATH + pd.getString("id") + ".html"));
    里面的路径, 需要查看freemarker中对数值的处理

    点赞 评论
  • qq_28485229
    qq_28485229 2018-01-25 02:58

    看下FileWriter out = new FileWriter(new File(FREEMARKER_PATH + pd.getString("id") + ".html"));
    这个的路径, 需要查看freemarker中对数值的处理

    点赞 评论
  • Harryqu123
    Harryqu123 2018-01-25 08:48

    看下FileWriter out = new FileWriter(new File(FREEMARKER_PATH + pd.getString("id") + ".html"));
    这个的路径, 需要查看freemarker中对数值的处理

    点赞 评论
  • qq_35770741
    冲天猴Corbett 2018-01-27 06:28

    template.process(java.lang.Object dataModel, java.io.Writer out); 这个方法中需要两个参数,第一个是Object类型的,通过查阅官方文档,第一个参数可放入Map或者是JavaBean还可以是实现TemplateHashModel的对象。之前是放入了Map对象,可能是因为在map对象中的参数值问题导致数组越界,后来我改为传入一个JavaBean对象,把需要传递的参数封装为JavaBean。问题解决。

    点赞 评论

相关推荐