thymeleaf模板引擎shiro集成框架
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集成框架的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 组策略对应于注册表位置汇总
- 下一篇: 浅谈Solr和ElasticSearch