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>
...
本文详细介绍SpringBoot项目中集成Shiro权限管理的过程,包括添加Maven依赖、配置FreeMarkerConfigurer解决页面404问题及使用Shiro标签读取会话信息等关键步骤。
1401

被折叠的 条评论
为什么被折叠?



