导航

freemarker中使用shiro标签

Posted on 2014-09-02 11:49  eastson  阅读(989)  评论(0编辑  收藏  举报

地址:https://github.com/jagregory/shiro-freemarker-tags
下载该jar包 或者源代码文件复制到自己工程的lib下或者package中 


如果使用spring MVC,请看http://www.woxplife.com/articles/473.html 
如果单独使用Freemarker 比如使用模板生成静态页, 在相关的类中加入如下代码: 

Configuration cfg = new Configuration(); 
cfg.setDefaultEncoding(“UTF-8”); 
cfg.setSharedVariable("shiro", new ShiroTags()); 

然后在ftl页面中使用tag: 

<@shiro.hasRole name=”admin”>Hello admin!</@shiro.hasRole>