thymeleaf模板整合shiro标签

来源:互联网 发布:windows api pdf 编辑:程序博客网 时间:2024/06/06 05:11

一、引入依赖

<dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf-spring4</artifactId><version>3.0.5.RELEASE</version></dependency><dependency>    <groupId>com.github.theborakompanioni</groupId>    <artifactId>thymeleaf-extras-shiro</artifactId>    <version>2.0.0</version></dependency>
二、配置

<bean id="templateResolver"class="z3.dbus.web.mvc.Z3ThymeleafViewResolver"><property name="prefix" value="/WEB-INF/view/" /><property name="suffix" value=".html" /><!-- HTML is the default value, added here for the sake of clarity. --><property name="templateMode" value="HTML" /><!-- Template cache is true by default. Set to false if you want --><!-- templates to be automatically updated when modified. --><property name="cacheable" value="true" /></bean><bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine"><property name="templateResolver" ref="templateResolver" /><property name="enableSpringELCompiler" value="true" /><property name="additionalDialects">      <set>        <bean class="at.pollux.thymeleaf.shiro.dialect.ShiroDialect"/>      </set>      </property> </bean>

三、标签使用

1、加入html命名空间

<html xmlns:th="http://www.thymeleaf.org"      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"        xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">  
2、加入shiro标签

<shiro:guest>  <a>登录</a> <a>注册</a></shiro:guest>  <shiro:user>  欢迎<shiro:principal property="name"/></shiro:user> 



1 0
原创粉丝点击