前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >jfinal自定义freemarker标签

jfinal自定义freemarker标签

作者头像
冷冷
发布2018-02-08 11:49:29
6030
发布2018-02-08 11:49:29
举报
文章被收录于专栏:冷冷冷冷

jfinal自定义freemarker标签


代码语言:javascript
复制
    1. config修改freemarkerrender
    public void afterJFinalStart() {
        super.afterJFinalStart();
        FreeMarkerRender.getConfiguration().setSharedVariable("bitch",new LabelDirective());
    }
    
    2.添加对应的标签方法实现
    public class LabelDirective implements TemplateDirectiveModel {
        public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
        // 真正开始处理输出内容
        List<User> users = new ArrayList<User>();
        users.add(new User(11, "a", "AAA"));
        users.add(new User(22, "b", "BBB"));
        users.add(new User(33, "c", "CCC"));
        environment.setVariable("users", ObjectWrapper.DEFAULT_WRAPPER.wrap(users));
        templateDirectiveBody.render(environment.getOut());
        }
    }
    
    3.页面调用
    <@bitch name="bitch">
        <#list users as user>
             <option value="${user.username}">${user.username}</option>
        </#list>
    </@bitch>

问题

使用<@bitch> </@bitch>标签时候 ==templateDirectiveBody== 空指针.

<></> 标签之间要有内容

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • jfinal自定义freemarker标签
  • 问题
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档