Shiro快速入门 —— 9.freemaker使用shiro标签
2019獨角獸企業重金招聘Python工程師標準>>>
本系列博文目錄:https://my.oschina.net/u/3452433/blog/907396
shiro-freemarker-tags項目jar包下載
freemaker默認情況下是不能使用shiro標簽進行權限控制的。
?
還好已經由大神James Gregory將此問題解決,并將源碼發布到了GitHub上面了。
GitHub上項目地址:https://github.com/jagregory/shiro-freemarker-tags
?
GitHub上的jar包下載報404,可以自己下載源碼打包或者使用我提供的源碼和jar包(用我的吧~~)
我的項目地址:http://git.oschina.net/imlichao/shiro-freemarker-tags
我的項目jar包地址:http://git.oschina.net/imlichao/shiro-freemarker-tags/raw/master/dist/shiro-freemarker-tags-0.1-SNAPSHOT.jar
?
jar包導入項目
如果項目沒有使用maven則可以直接添加到項目中
如果使用了maven可以發布到私服或者直接放到本地倉庫中進行引用
<dependency><groupId>com.jagregory.shiro</groupId><artifactId>freemarker</artifactId><version>0.1-SNAPSHOT</version></dependency>?
在freemaker中自定義shiro標簽
這個項目實質上就是實現了一套freemaker的自定義標簽,所我們需要自定義shiro標簽。
在freemaker配置文件中自定義標簽(例子為spring boot配置文件截取的)
/*** FreeMarker配置文件*/ @Configuration public class FreemarkerConfig {@Beanpublic FreeMarkerConfigurer freeMarkerConfigurer(FreeMarkerProperties freeMarkerProperties) {FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();configurer.setTemplateLoaderPaths(freeMarkerProperties.getTemplateLoaderPath()); //模板加載路徑默認 "classpath:/templates/"configurer.setDefaultEncoding("utf-8");//設置頁面默認編碼(不設置頁面中文亂碼)Map<String,Object> variables=new HashMap<String,Object>();variables.put("shiro", new ShiroTags());configurer.setFreemarkerVariables(variables);//添加shiro自定義標簽return configurer;}}?
在頁面使用shiro標簽
以上配置完成后,我們就可以在ftl頁面使用<@shiro>標簽了
給幾個例子
<!-- 游客內容 --> <@shiro.guest>Hello guest!</@shiro.guest><!-- 驗證權限 --> <@shiro.hasPermission name = "admin_customer_manage">會員詳情 </@shiro.hasPermission>?
?
?
轉載于:https://my.oschina.net/u/3452433/blog/901945
總結
以上是生活随笔為你收集整理的Shiro快速入门 —— 9.freemaker使用shiro标签的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微服务,微架构[五]之springboo
- 下一篇: centos6.5环境wget报错Una