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集成框架的更多相关文章

  1. 九、SpringBoot集成Thymeleaf模板引擎

    Thymeleaf咋读!??? 呵呵,是不是一脸懵逼...哥用我的大学四级英文知识告诉你吧:[θaimlif]. 啥玩意?不会音标?...那你就这样叫它吧:“赛母李府”,大部分中国人是听不出破绽的.. ...

  2. SpringBoot--- Shiro(拦截,认证)、Thymeleaf(模板引擎)

    SpringBoot--- Shiro(拦截,认证).Thymeleaf(模板引擎) 环境 IDEA :2020.1 SpringBoot: 2.3.3 Java : 8 版本依赖: ​ shiro- ...

  3. 【Springboot】Springboot整合Thymeleaf模板引擎

    Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...

  4. SpringBoot入门篇--使用Thymeleaf模板引擎进行页面的渲染

    在做WEB开发的时候,我们不可避免的就是在前端页面之间进行跳转,中间进行数据的查询等等操作.我们在使用SpringBoot之前包括我在内其实大部分都是用的是JSP页面,可以说使用的已经很熟悉.但是我们 ...

  5. Spring Boot2(五):使用Spring Boot结合Thymeleaf模板引擎使用总结

    一.Thymeleaf概述 一般来说,常用的模板引擎有JSP.Velocity.Freemarker.Thymeleaf . SpringBoot推荐的 Thymeleaf – 语法更简单,功能更强大 ...

  6. (二)SpringBoot基础篇- 静态资源的访问及Thymeleaf模板引擎的使用

    一.描述 在应用系统开发的过程中,不可避免的需要使用静态资源(浏览器看的懂,他可以有变量,例:HTML页面,css样式文件,文本,属性文件,图片等): 并且SpringBoot内置了Thymeleaf ...

  7. 三、thymeleaf模板引擎构建前台html, 后台使用 ModelAndView 和 Model 模型

    项目源码:https://github.com/y369q369/springBoot.git      ->     thymeleaf 私聊QQ: 1486866853 1.pom.xml中 ...

  8. SpringBoot使用thymeleaf模板引擎

    (1).添加pom依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...

  9. Spring Boot 2.0 整合Thymeleaf 模板引擎

    本节将和大家一起实战Spring Boot 2.0 和thymeleaf 模板引擎 1. 创建项目 2. 使用Spring Initlizr 快速创建Spring Boot 应用程序 3. 填写项目配 ...

随机推荐

  1. [LeetCode141]Linked List Cycle

    题目:Given a linked list, determine if it has a cycle in it. 判断一个链表是否有环 代码: /** * Definition for singl ...

  2. 如何知道 win10 的激活到期时间和期限等

    在“运行”里输入cmd,出来dos对话框后,输入下面的东西后,按Enterslmgr.vbs -dli (显示:操作系统版本.部分产品密钥.许可证状态)slmgr.vbs -dlv (显示:最为详尽的 ...

  3. Apple Watch 1.0 开发介绍 2.1 WatchKit Apps UI要点

    实现app的开始是定义storyboard场景.每个场景定义了app的一部分界面.可以为不同的尺寸自定义场景. 组装storyboard界面 WatchKit app和iOS app的布局模式不同.组 ...

  4. Android-管理Activity生命周期 -重新创建Activity

    按照正常的app行为,很少情况下activity会销毁,只有当用户点击了返回按钮或者activity通过调用finish()发出销毁信号.系统也有可能销毁activity如果它是停止状态并且很久没有使 ...

  5. android ListView优化

    android ListView通过优化重用历史缓存实现.listview相应的数据适配器一般使用自己定义BaseAdapter子类,重用历史缓冲区来提高性能. 例如,下面的示例代码演示: 1.lis ...

  6. Java写程序猿专访String2

    2.如何推理2一个字符串是否具有相同的字符 例如"aaaabbc"随着"abcbaaa" 2种思想 import java.lang.reflect.Array ...

  7. Unity 3D使用GameObject创建一个简单的可移动物体

    于Unity 3D游戏的开发.游戏脚本需要3D模拟组合,该脚本将被写入阻力3D为了达到效果对象. 以下是一个小实例,使用Unity 3D实现一个可控制移动的小人.小人能够向前.向后.向左和向右移动. ...

  8. CodeForces 398B 概率DP 记忆化搜索

    题目:http://codeforces.com/contest/398/problem/B 有点似曾相识的感觉,记忆中上次那个跟这个相似的 我是用了 暴力搜索过掉的,今天这个肯定不行了,dp方程想了 ...

  9. android怎么在launcher改动内置apk的icon

    找到launcher下的IconCache中加入变量用来存储要改动apk的包名 及要改动成的icon private String[] className = {"com.google.an ...

  10. 关于继承modelDriven接口action的ajax来电参数

    例如   Model类如下面,Teacher,public class Teacher{  private Integer id. priavte  String name;  private Sch ...