freemarker中使用shiro标签
来源:互联网 发布:网络问诊国家政策 编辑:程序博客网 时间:2024/05/19 19:32
继承FreeMarkerConfigurer类,重写afterPropertiesSet()方法;
import com.jagregory.shiro.freemarker.ShiroTags;import freemarker.template.TemplateException;import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;import java.io.IOException;/** * 继承FreeMarkerConfigurer类,重写afterPropertiesSet()方法; * 集成shiroTags标签 * Created by zsc on 2016/1/5. */public class ShiroTagFreeMarkerConfigurer extends FreeMarkerConfigurer { @Override public void afterPropertiesSet() throws IOException, TemplateException { super.afterPropertiesSet(); this.getConfiguration().setSharedVariable("shiro", new ShiroTags()); }}
<beanclass="com.shiro.shiro.ShiroTagFreeMarkerConfigurer"><property name="templateLoaderPath" value="/WEB-INF/page/" /><property name="freemarkerSettings"><props><prop key="defaultEncoding">UTF-8</prop></props></property></bean>
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer" 就把这个class改成
ShiroTagFreeMarkerConfigurer这个类就可以了
然后直接在前台调用:
guest标签:验证当前用户是否为“访客”,即未认证(包含未记住)的用户;shiro标签:<shiro:guest></shiro:guest> ;freemark中: <@shiro.guest> </@shiro.guest>
user标签:认证通过或已记住的用户 shiro标签:<shiro:user> </shiro:user> ;freemark中: <@shiro.user> </@shiro.user>
authenticated标签:已认证通过的用户。不包含已记住的用户,这是与user标签的区别所在。 shiro标签:<shiro:authenticated> </shiro:authenticated>;freemark中: <@shiro.authenticated></@shiro.authenticated>
notAuthenticated标签:未认证通过的用户。与authenticated标签相对。 shiro标签:<shiro:notAuthenticated> </shiro:notAuthenticated>;freemark中: <@shiro.notAuthenticated></@shiro.notAuthenticated>
principal标签:输出当前用户信息,通常为登录帐号信息 shiro标签:Hello, <@shiro.principal property="name" /> ;freemarker中: Hello, <@shiro.principal property="name" />, how are you today?
hasRole标签:验证当前用户是否属于该角色 ,shiro标签: <shiro:hasRole name="administrator"> Administer the system </shiro:hasRole> ;freemarker中:<@shiro.hasRole name=”admin”>Hello admin!</@shiro.hasRole>
hasAnyRoles标签:验证当前用户是否属于这些角色中的任何一个,角色之间逗号分隔 ,shiro标签: <shiro:hasAnyRoles name="admin,user,operator"> Administer the system </shiro:hasAnyRoles> ;freemarker中:<@shiro.hasAnyRoles name="admin,user,operator">Hello admin!</@shiro.hasAnyRoles>
hasPermission标签:验证当前用户是否拥有该权限 ,shiro标签: <shiro:hasPermission name="/order:*"> 订单 </shiro:hasPermission> ;freemarker中:<@shiro.hasPermission name="/order:*">订单/@shiro.hasPermission>
lacksRole标签:验证当前用户不属于该角色,与hasRole标签想反,shiro标签: <shiro:hasRole name="admin"> Administer the system </shiro:hasRole> ;freemarker中:<@shiro.hasRole name="admin">Hello admin!</@shiro.hasRole>
lacksPermission标签:验证当前用户不拥有某种权限,与hasPermission标签是相对的,shiro标签: <shiro:lacksPermission name="/order:*"> trade </shiro:lacksPermission> ;freemarker中:<@shiro.lacksPermission name="/order:*">trade</@shiro.lacksPermission>
- freemarker中使用shiro标签
- freemarker中使用shiro标签
- freemarker中使用shiro标签
- 在FreeMarker框架中使用Shiro的Tag标签
- 在FreeMarker框架中使用Shiro的Tag标签
- Apache Shiro 整合Spring 进行权限验证 以及在Freemarker中使用shiro标签
- Apache Shiro 整合Spring 进行权限验证 以及在Freemarker中使用shiro标签
- Apache Shiro 整合Spring 进行权限验证 以及在Freemarker中使用shiro标签
- Apache Shiro 整合Spring 进行权限验证 以及在Freemarker中使用shiro标签
- freemarker集成shiro标签
- freemarker 在FreeMarker中使用JSP标签
- shiro与freemarker标签集成
- shiro与freemarker标签集成
- 添加freemarker的shiro标签
- 在freemarker中使用jsp标签 Using FreeMarker with servlets
- 在freemarker中使用jsp标签 Using FreeMarker with servlets
- struts2+FreeMarker中使用JSP标签
- 在Freemarker中使用struts2标签
- CSS 盒子模型
- 并发编程--互斥锁ReentrantLock
- stderr和stdout详细解说
- 加载指定文件的方式,使用getResourceAsStream("fileName")
- GUI_对四则运算案例加入校验和提示
- freemarker中使用shiro标签
- tensorflow实战系列(四)基于TensorFlow构建AlexNet代码解析
- 关于Xfermode中src和dsc的问题
- Java 获取前端页面代码段中img标签的src属性值,即获取图片Url
- 关于TabLayout遇到的坑
- Linux的ioctl和fcntl
- BZOJ4811 [Ynoi2017]由乃的OJ
- 按选择的开始时间和结束时间算出中间的所有年月日
- left join on 和where条件的放置 区别