1.shiro标签在jsp页面的使用:
直接引入标签库:<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
2.shiro标签在html页面的使用:
html不同于jsp,属于静态页面,只有html原生标签库,如果想在html页面使用shiro标签,需要搭配thymeleaf来进行引用
2.1导入依赖
2.2springmvc配置文件注册视图解析器及方言解释器
<!--使用thyme leaf-->
<!--视图解析器-->
<bean id="templateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
<property name="templateMode" value="HTML"></property>
<property name="cacheable" value="false"/>
<property name="characterEncoding" value="UTF-8"/>
</bean>
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver"></property>
<property name="additionalDialects">
<set>
<!--方言解释器-->
<bean class="at.pollux.thymeleaf.shiro.dialect.ShiroDialect"/>
</set>
</property>
</bean>
<bean id="viewResolver" class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine"/>
<property name="characterEncoding" value="UTF-8"/>
</bean>
2.3页面使用
<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2 shiro:authenticated><a>已认证</a></h2>
<h2 shiro:guest=""><a>游客访问</a></h2>
<shiro:authenticated><a>已认证</a></shiro:authenticated>
<shiro:guest><a>游客访问</a></shiro:guest>
<shiro:hasAnyPermissions name="USER_QUERY"><a>查询</a></shiro:hasAnyPermissions>
</body>
</html>
2.4效果