Springboot项目 freemarker 引入shiro 标签

springboot集成shiro权限过程略过

一、添加maven 依赖

<dependency>
  <groupId>net.mingsoft</groupId>
  <artifactId>shiro-freemarker-tags</artifactId>
  <version>0.1</version>
</dependency>

二、注入FreeMarkerConfigurer,未指定templateLoaderPath时遇到过跳转到页面404问题

@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() throws IOException, TemplateException {
    FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
    freeMarkerConfigurer.setTemplateLoaderPath("classpath:templates/");
    freemarker.template.Configuration configuration = freeMarkerConfigurer.createConfiguration();
    configuration.setDefaultEncoding("UTF-8");
    //这里可以添加其他共享变量 比如sso登录地址
    configuration.setSharedVariable("shiro", new ShiroTags());
    freeMarkerConfigurer.setConfiguration(configuration);
    return freeMarkerConfigurer;
}

三、shiro标签

1、session中读取登录人信息

<@shiro.principal/>

2、带有loginName属性的对象转换为Prinipal后保存在session

<shiro:principal property="loginName" />

3、带有loginName属性的Json(个人使用的是FashJson对象)转换为Prinipal后保存在session,使用freemarker标签处理Json

<#assign loginInfo><@shiro.principal/></#assign>
<#assign data=loginInfo?eval>
用户:${data.loginName!""}

4、其他shiro标签使用

<@shiro.hasPermission name="权限编码">
    ...
</@shiro.hasPermission>

...

转载于:https://my.oschina.net/jeakiry/blog/1814811

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值