freemarker中使用shiro標籤

繼承FreeMarkerConfigurer類,重寫afterPropertiesSet()方法;


需要加入jar包    shiro-freemarker-tags-0.1-SNAPSHOT.jar





如果你之前配置了

<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"   就把這個class改成


這個類就可以了


然後直接在前臺調用:

    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> 

發佈了2 篇原創文章 · 獲贊 10 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章