freemarker中使用shiro标签

时间:2023-03-09 05:24:34
freemarker中使用shiro标签

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

如果使用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>