shiro标签在html页面的使用

本文介绍了如何在HTML页面中使用Thymeleaf和Shiro标签库,通过SpringMVC配置视图解析器和方言解释器,实现实体认证、权限检查等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值