主题:beetl如何实现像动态页面静态化?

laram 2019年10月04日 29

第一个问题:beetl如何实现像Thymeleaf中的静态化:https://blog.csdn.net/qq_38762237/article/details/89948842


第二个问题,我参考文档中的示例写了个demo,代码如下

String root = System.getProperty("user.dir") + File.separator + "/src/main/resources/templates";FileResourceLoader fileResourceLoader = new FileResourceLoader(root,"utf-8");Configuration cfg = Configuration.defaultConfiguration();GroupTemplate gt = new GroupTemplate(fileResourceLoader,cfg);Template template = gt.getTemplate("/" + "detail" + ".html");List<DownloadPopularArticle> popularArticle = downloadPopularArticleService.findList(new DownloadPopularArticle());List<DownloadPopularDw> popularDw = downloadPopularDwService.findList(new DownloadPopularDw());List<DownloadPopularTag> popularTags = downloadPopularTagService.findList(new DownloadPopularTag());Page<DownloadSite> page = downloadSiteService.findPage(downloadSite);for (DownloadSite site : page.getList()) {
    if(StringUtils.isNotBlank(site.getTags())){
        List<String> result = Arrays.asList(site.getTags().split(","));        for (String tag : result) {
            DictData db = new DictData();            db.setDictType("download_site_tag");            db.getSqlMap().getWhere().and("dict_value", QueryType.EQ,tag);            DictData byEntity = dictDataDao.getByEntity(db);            if(byEntity != null){
                tags.add(byEntity.getDictLabelOrig());            }
        }
    }
    String result = "xxxxx";    String key = site.getTitle();    if(StringUtils.isNotBlank(key)){
        String [] arr = key.split("\\s+");        result = StringUtils.join(arr, ",");    }
    String siteName = DictUtils.getDictLabel("download_site_name", site.getWebname(), "xxxxx");    String keywords = result;    template.binding("site",site);    template.binding("ctxStatic","/static");    template.binding("domain","http://www.xxxx.com");    template.binding("siteName",siteName);    template.binding("keywords",keywords);    String category = "all";    if(StringUtils.isNotBlank(site.getCategory())){
        category = site.getCategory();    }
    template.binding("category",category);    //热门下载    template.binding("popularDw",popularDw);    template.binding("tags",tags);    template.binding("popularTags",popularTags);    //热门文章    template.binding("popularArticle",popularArticle);    FileWriter fileWriter = new FileWriter(System.getProperty("user.dir") + File.separator + "/src/main/resources/templates/" + site.getCid() + ".html");    template.renderTo(fileWriter);}

html页面中调用了一些自定义的方法,在渲染的时候,总是报错,提示什么自定义的方法找不到啥的。

闲大赋 6天前

看看自定义方法找到没,你贴的这个代码太乱了》。。错误提示也没有贴出来