springboot+mybatis+maven角色权限框架
概述
详细
一、前言
1,java服务端开发人员
2,初级人员开发人员
3,了解spring springboot+maven+mybatis+shrio
3,对框架基本掌握
(2) 你需要准备什么?
1,积极主动学习
2,java框架搭建部署
3,java后端几大框架掌握如(spring springboot maven mybatis)
二、前期准备工作
软件环境:eclipse
官方下载:https://www.eclipse.org/downloads/
1丶基本需求
1,实现后台权限管理
用户管理:用户是系统操作者,该功能主要完成系统用户配置。
机构管理:配置系统组织机构(公司、部门、小组),树结构展现,可随意调整上下级。
区域管理:系统城市区域模型,如:国家、省市、地市、区县的维护。
菜单管理:配置系统菜单,操作权限,按钮权限标识等。
角色管理:角色菜单权限分配、设置角色按机构进行数据范围权限划分。
字典管理:对系统中经常使用的一些较为固定的数据进行维护,如:是否、男女、类别、级别等。
操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。
连接池监视:监视当期系统数据库连接池状态,可进行分析SQL找出系统性能瓶颈。
工作流引擎:实现业务工单流转、在线流程设计器。
前端
1. Bootstrap
2. jQuery
3. bootstrap-table
4. layer
5. jsTree
6. summernote
7. jquery-validate
8. jquery-treegrid
三、项目结构
项目目录结构

数据库表

eclipse导入,选择到项目以后,选择maven,一路默认选择到打开项目
sql文件复制并在mysql中运行创建好数据库表
打开application-dev.yml文件,修改其中的数据库连接+用户名+密码。另外一个application-pro.yml文件是 生产环境使用,具体使用哪一个是在application.yml中指定
server:
port: 8080
tomcat:
uri-encoding: utf-8
context-path: /
spring:
thymeleaf:
mode: LEGACYHTML5
cache: false
jackson:
time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss
profiles:
active: dev
http:
multipart:
max-file-size: 30Mb
max-request-size: 30Mb
devtools:
restart:
enabled: true
mybatis:
configuration:
map-underscore-to-camel-case: true
mapper-locations: mybatis/**/*Mapper.xml
typeAliasesPackage: com.system.**.domain
四、程序实现
loginCotrller 登录接口
package com.system.contrller; import java.util.List; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody; import com.system.common.annotation.Log;
import com.system.common.domain.Tree;
import com.system.common.utils.MD5Utils;
import com.system.common.utils.R;
import com.system.common.utils.ShiroUtils;
import com.system.domain.MenuDO;
import com.system.service.MenuService; @Controller
public class loginCotrller extends BaseController {
private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired
MenuService menuService; @GetMapping({ "/", "" })
String welcome(Model model) {
return "redirect:/login";
} @Log("请求访问主页")
@GetMapping({ "/index" })
String index(Model model) {
List<Tree<MenuDO>> menus = menuService.listMenuTree(getUserId());
model.addAttribute("menus", menus);
model.addAttribute("name", getUser().getName());
model.addAttribute("username", getUser().getUsername());
return "index_v1";
} @GetMapping("/login")
String login() {
return "login";
} @Log("登录")
@PostMapping(value="/login")
@ResponseBody
R ajaxLogin(String username, String password) {
password = MD5Utils.encrypt(username, password);
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
Subject subject = SecurityUtils.getSubject();
try {
subject.login(token);
return R.ok();
} catch (AuthenticationException e) {
return R.error("用户或密码错误");
}
} @GetMapping("/logout")
String logout() {
ShiroUtils.logout();
return "redirect:/login";
} @GetMapping("/main")
String main() {
return "main";
} @GetMapping("/403")
String error403() {
return "403";
} }
如何配置让shiro执行我们的自定义sessionManager呢?下面看ShiroConfig类。
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.SessionListener;
import org.apache.shiro.session.mgt.SessionManager;
import org.apache.shiro.session.mgt.eis.MemorySessionDAO;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import com.system.shiro.UserRealm; import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap; @Configuration
public class ShiroConfig {
@Bean
public EhCacheManager getEhCacheManager() {
EhCacheManager em = new EhCacheManager();
em.setCacheManagerConfigFile("classpath:config/ehcache.xml");
return em;
} @Bean
UserRealm userRealm(EhCacheManager cacheManager) {
UserRealm userRealm = new UserRealm();
userRealm.setCacheManager(cacheManager);
return userRealm;
}
@Bean
SessionDAO sessionDAO() {
MemorySessionDAO sessionDAO = new MemorySessionDAO();
return sessionDAO;
} @Bean
public SessionManager sessionManager() {
DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
Collection<SessionListener> listeners = new ArrayList<SessionListener>();
listeners.add(new BDSessionListener());
sessionManager.setSessionListeners(listeners);
sessionManager.setSessionDAO(sessionDAO());
return sessionManager;
} @Bean
SecurityManager securityManager(UserRealm userRealm) {
DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
manager.setRealm(userRealm);
manager.setCacheManager(getEhCacheManager());
manager.setSessionManager(sessionManager());
return manager;
} @Bean
ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
shiroFilterFactoryBean.setSecurityManager(securityManager);
shiroFilterFactoryBean.setLoginUrl("/login");
shiroFilterFactoryBean.setSuccessUrl("/index");
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
filterChainDefinitionMap.put("/css/**", "anon");
filterChainDefinitionMap.put("/js/**", "anon");
filterChainDefinitionMap.put("/fonts/**", "anon");
filterChainDefinitionMap.put("/img/**", "anon");
filterChainDefinitionMap.put("/qrimg/**", "anon");
filterChainDefinitionMap.put("/docs/**", "anon");
filterChainDefinitionMap.put("/druid/**", "anon");
filterChainDefinitionMap.put("/upload/**", "anon");
filterChainDefinitionMap.put("/files/**", "anon");
filterChainDefinitionMap.put("/logout", "logout");
filterChainDefinitionMap.put("/", "anon");
filterChainDefinitionMap.put("/blog", "anon");
filterChainDefinitionMap.put("/wx/**", "anon");
filterChainDefinitionMap.put("/dist/**", "anon");
filterChainDefinitionMap.put("/blog/open/**", "anon");
filterChainDefinitionMap.put("/**", "anon");
filterChainDefinitionMap.put("/swagger-ui/**", "anon"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
} @Bean("lifecycleBeanPostProcessor")
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
return new LifecycleBeanPostProcessor();
} @Bean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator proxyCreator = new DefaultAdvisorAutoProxyCreator();
proxyCreator.setProxyTargetClass(true);
return proxyCreator;
} @Bean
public ShiroDialect shiroDialect() {
return new ShiroDialect();
} @Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(
@Qualifier("securityManager") SecurityManager securityManager) {
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
return authorizationAttributeSourceAdvisor;
} }
五、项目运行效果
代码太多不一一贴出来了让我们看下展示效果
访问地址 localhost:8080 如图
1,用户管理

2,角色管理


3,系统菜单

注:本文著作权归作者,由demo大师发表,拒绝转载,转载需要作者授权
springboot+mybatis+maven角色权限框架的更多相关文章
- IDEA+SpringBoot+Mybatis+maven分布式项目框架的搭建
参考文章:https://blog.csdn.net/qq_34410726/article/details/98214992 一.maven分布式工程的基本架构 demo #父工程模块,主要用来定 ...
- 基于Maven的Springboot+Mybatis+Druid+Swagger2+mybatis-generator框架环境搭建
基于Maven的Springboot+Mybatis+Druid+Swagger2+mybatis-generator框架环境搭建 前言 最近做回后台开发,重新抓起以前学过的SSM(Spring+Sp ...
- 菜鸟——springboot+mybatis+maven
网上找了很多资料,学习如何搭建springboot,由于刚刚接触springboot,不是很熟练,通过参考网上别人搭建的例子,自己也搭建了一个简单的springboot+mybaits+maven 网 ...
- SpringBoot+Mybatis+Maven+MySQL逆向工程实现增删改查
SpringBoot+Mybatis+MySQL+MAVEN逆向工程实现增删改查 这两天简单学习了下SpringBoot,发现这玩意配置起来是真的方便,相比于SpringMVC+Spring的配置简直 ...
- Spring-boot+Mybatis+Maven+MySql搭建实例
转自:https://www.jianshu.com/p/95fb7be049ae 最近读了spring-boot开发手册,spring-boot相比于spring-mvc封装了很多常用的依赖,并且内 ...
- SpringBoot+Mybatis+Maven+MySql小案例
数据准备: 建表t_user ,插入数据..... 创建工程 构建pom.xml <?xml version="1.0" encoding="UTF-8" ...
- Java微服务(Spring-boot+MyBatis+Maven)入门教程
1,项目创建 新建maven项目,如下图: 选择路径,下一步 输入1和2的内容,点完成 项目创建完毕,结构如下图所示: 填写pom.xml里内容,为了用于打包,3必须选择jar,4和5按图上填写 ...
- springboot+mybatis+druid+atomikos框架搭建及测试
前言 因为最近公司项目升级,需要将外网数据库的信息导入到内网数据库内.于是找了一些springboot多数据源的文章来看,同时也亲自动手实践.可是过程中也踩了不少的坑,主要原因是我看的文章大部分都是s ...
- springboot mybatis 后台框架平台 集成代码生成器 shiro 权限
1.代码生成器: [正反双向](单表.主表.明细表.树形表,快速开发利器)freemaker模版技术 ,0个代码不用写,生成完整的一个模块,带页面.建表sql脚本.处理类.service等完整模块2. ...
随机推荐
- 【已解决】unity4.2.0f4 导出Android工程报错:Error building Player: ArgumentException: Illegal characters in path. [unity导出android工程 报错,路径含有非法字符]
使用unity3D开发的一个客户端,需要导出为Android工程,然后接入一些第三方android SDK. unity版本 操作系统为: OS 名称: Microsoft Windows 7 旗舰版 ...
- frp官方中文文档
frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp, udp, http, https 协议. 目录 frp 的作用 开发状态 架构 使用示例 通过 ssh 访问公司内网机器 通过自定义 ...
- lazarus编译X86/X64的程序
一.以下两个包都得安装,不然 64 位 lazarus 编译不出 32 位的 DLL. lazarus-1.8.4-fpc-3.0.4-win64.exe lazarus-1.8.4-fpc-3.0. ...
- Go语言之进阶篇连接mysql
一.Go连接mysql 1.mysql驱动 地址:https://github.com/Go-SQL-Driver/MySQL 说明: sql.Open()函数用来打开一个注册过的数据库驱动,Go-M ...
- SharePoint自定义程序页面部署 不用重启IIS
SharePoint的部署方式默认是部署WSP包,尤其是有多个前端的时候WSP包的部署显得非常方便和快捷,但是WSP的部署需要重启整个IIS服务会造成SharePoint站点一段时间不能访问.结合自己 ...
- Android -- EventBus使用
EventBus EventBus是一个Android端优化的publish/subscribe消息总线,简化了应用程序内各组件间.组件与后台线程间的通信.比如请求网络,等网络返回时通过Handler ...
- 【转】TensorFlow四种Cross Entropy算法实现和应用
http://www.jianshu.com/p/75f7e60dae95 作者:陈迪豪 来源:CSDNhttp://dataunion.org/26447.html 交叉熵介绍 交叉熵(Cross ...
- SearchBySql
Java: public List<Accountingdisclosure> searchAccountingdisclosuresBySql(String sqlStr)throws ...
- esUtil.h中的m变量报错
引用了OpenGL ES自带的esUtil.h, 编译的时候报错: typedef struct { GLfloat m[4][4]; } ESMatrix; ...
- Python爬虫实战(二):爬百度贴吧
代码: # _*_ coding:utf-8 _*_ import urllib import urllib2 import re class Tool: removingImg = re.compi ...