首页 > 其他 > 详细

thymeleaf模板引擎shiro集成框架

时间:2015-10-13 13:39:18      阅读:3598      评论:0      收藏:0      [点我收藏+]

shiro权限框架。前端验证jsp设计。间tag它只能用于jsp系列模板引擎。

使用最近项目thymeleaf作为前端模板引擎,采用HTML档,未出台shiro的tag lib,假设你想利用这段时间shiro如果,可以引入 thymeleaf-extras-shiro.jar这个拓展包来曲线实现shiro的前端验证。

在pom.xml中增加例如以下依赖:

		<dependency>
			<groupId>com.github.theborakompanioni</groupId>
			<artifactId>thymeleaf-extras-shiro</artifactId>
			<version>1.0.2</version>
		</dependency>

关于版本号,能够在maven仓库中查询:http://mvnrepository.com/artifact/com.github.theborakompanioni/thymeleaf-extras-shiro/1.0.2

thymeleaf-extras-shiro.jar在git hub的地址:https://github.com/theborakompanioni/thymeleaf-extras-shiro。上面有详细的使用说明。

引入jar包后,我们要简单设置一下thymeleaf的引擎:

<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
  <property name="templateResolver" ref="templateResolver" />
  <property name="additionalDialects">
    <set>
      <bean class="at.pollux.thymeleaf.shiro.dialect.ShiroDialect"/>
    </set>
  </property>
</bean>


或者假设使用的是Java代码配置的话:

	public SpringTemplateEngine templateEngine() {
		SpringTemplateEngine templateEngine = new SpringTemplateEngine();
		templateEngine.setTemplateResolver(templateResolver());
		 
		Set<IDialect> additionalDialects = new HashSet<IDialect>();
		
		additionalDialects.add(new ShiroDialect());
		
		templateEngine.setAdditionalDialects(additionalDialects);
		
		return templateEngine;
	}

然后就能够在页面中使用thymeleaf化的shiro标签来进行前端验证了。

shiro本身的标签有限,没有hasAnyPermission标签,我在之前的一篇文章中《自己定义shiro标签》有写过jsp标签的版本号。事实上,在这里假设使用的是thymeleaf,也能够自己定义拓展一下shiro的hasAnyPermission。

将下载下来的thymeleaf-extras-shiro.jar打开,会有一个shiro-dialect.xml的文件,这里定义了thymeleaf的shiro属性,我们也能够依据这里面的样例进行简单拓展。
这里事实上是在拓展thymeleaf,官方文档中有具体的说明和简单的例子,对比文档,学习会更快。



版权声明:本文博主原创文章,博客,未经同意不得转载。

thymeleaf模板引擎shiro集成框架

原文:http://www.cnblogs.com/mengfanrong/p/4874187.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!