spring mvc + shiro +thymeleaf 扩展使用shiro tags页面标签
2017-03-17 13:20
423 查看
先看官方说明:
Apache Shiro provides a Subject-aware JSP/GSP tag library that allows you to control your JSP, JSTL or GSP page output based on the current Subject's state. This is quite useful for personalizing views
based on the identity and authorization state of the current user viewing the web page.
Tag Library Configuration
The Tag Library Descriptor (TLD) file is bundled in shiro-web.jar in the META-INF/shiro.tld file. To use any of the tags, add the following line to the top of your JSP page (or wherever you define page
directives):
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
We've used the shiro prefix to indicate the shiro tag library namespace, but you can assign whatever name you like.
Now we'll cover each tag and show how it might be used to render a page.
官网对于shiro标签说明 ,它支持jsp,jstl,gsp等前端技术,但是不支持themleaf。
但是在https://github.com/theborakompanioni/thymeleaf-extras-shiro中提供一个
thymeleaf-extras-shiro技术,相当于thymeleaf的扩展。
maven 配置如下:
<!--thymeleaf-shiro-extras-->
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>1.1.0</version>
</dependency>
spring mvc 配置文件中配置如下:
<!--thymeleaf 视图处理器配置-->
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<property name="characterEncoding" value="UTF-8"/>
</bean>
<bean id="templateEngine"
class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
<property name="additionalDialects">
<set>
<bean class="at.pollux.thymeleaf.shiro.dialect.ShiroDialect"/>
</set>
</property>
</bean>
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
<property name="characterEncoding" value="UTF-8"/>
</bean>
页面则可以使用 shiro标签:
<ul class="nav nav-tabs nav-stacked main-menu" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<li
shiro:hasPermission ="SearchFile">
<a href="fileanager.html" th:href="@{/test/adminUser/fileManager}">
<i class="icon-bar-chart"></i><span class="hidden-tablet"> 文件管理</span>
</a>
</li>
</ul>
官方说明:https://github.com/theborakompanioni/thymeleaf-extras-shiro
Apache Shiro provides a Subject-aware JSP/GSP tag library that allows you to control your JSP, JSTL or GSP page output based on the current Subject's state. This is quite useful for personalizing views
based on the identity and authorization state of the current user viewing the web page.
Tag Library Configuration
The Tag Library Descriptor (TLD) file is bundled in shiro-web.jar in the META-INF/shiro.tld file. To use any of the tags, add the following line to the top of your JSP page (or wherever you define page
directives):
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
We've used the shiro prefix to indicate the shiro tag library namespace, but you can assign whatever name you like.
Now we'll cover each tag and show how it might be used to render a page.
官网对于shiro标签说明 ,它支持jsp,jstl,gsp等前端技术,但是不支持themleaf。
但是在https://github.com/theborakompanioni/thymeleaf-extras-shiro中提供一个
thymeleaf-extras-shiro技术,相当于thymeleaf的扩展。
maven 配置如下:
<!--thymeleaf-shiro-extras-->
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>1.1.0</version>
</dependency>
spring mvc 配置文件中配置如下:
<!--thymeleaf 视图处理器配置-->
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<property name="characterEncoding" value="UTF-8"/>
</bean>
<bean id="templateEngine"
class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
<property name="additionalDialects">
<set>
<bean class="at.pollux.thymeleaf.shiro.dialect.ShiroDialect"/>
</set>
</property>
</bean>
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
<property name="characterEncoding" value="UTF-8"/>
</bean>
页面则可以使用 shiro标签:
<ul class="nav nav-tabs nav-stacked main-menu" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<li
shiro:hasPermission ="SearchFile">
<a href="fileanager.html" th:href="@{/test/adminUser/fileManager}">
<i class="icon-bar-chart"></i><span class="hidden-tablet"> 文件管理</span>
</a>
</li>
</ul>
官方说明:https://github.com/theborakompanioni/thymeleaf-extras-shiro
相关文章推荐
- springboot+shiro实现登录系数限定,thymeleaf中使用shiro标签
- springboot 在ftl页面上使用shiro标签的实例代码
- 关于spring 3.0.5的<mvc:resources> 标签的使用
- 关于spring 3.0.5的<mvc:resources> 标签的使用
- 【uploadify】使用Uploadify+SpringMVC实现不用From文件页面无刷上传
- ehcache配置:使用Spring+SpringMVC+Mybatis或者有shiro【转】
- 关于spring 3.0.5的<mvc:resources> 标签的使用
- 关于shiro+springMVC整合使用的问题
- Spring Boot Shiro 权限信息缓存处理,记住我,thymleaf使用shiro标签
- Apache Shiro 整合Spring 进行权限验证 以及在Freemarker中使用shiro标签
- spring<mvc:resources> 标签的使用 静态资源的访问
- 关于spring 3.0.5的<mvc:resources> 标签的使用
- Apache Shiro 整合Spring 进行权限验证 以及在Freemarker中使用shiro标签
- 在Spring+FreeMarker框架中使用Shiro的Tag标签
- thymeleaf 与 jsp 同时使用 for spring mvc
- 关于spring <mvc:resources> 标签的使用
- shiro +springmvc+freemarker session问题处理 shiro无法记录登陆前页面问题
- ehcache配置:使用Spring+SpringMVC+Mybatis或者有shiro【转】
- SpringMVC+shiro权限拦截(不使用shiro注解方式)