当前位置:   article > 正文

springboot+spring security + mybatis 从数据库动态地配置访问权限(小案例)_springsecurity mybatis

springsecurity mybatis

前言;

本来想说点东西,为下文做个引子;算了,太菜了,等我成为大牛再来哔哔赖赖吧!目前小白一个,大佬勿喷。学习记录用,相互勉励,共创辉煌。

一、准备数据库

  1. CREATE DATABASE security;
  2. USE `security`;
  3. /*Table structure for table `menu` */
  4. DROP TABLE IF EXISTS `menu`;
  5. CREATE TABLE `menu` (
  6. `id` int(11) NOT NULL AUTO_INCREMENT,
  7. `pattern` varchar(128) DEFAULT NULL,
  8. PRIMARY KEY (`id`)
  9. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
  10. /*Data for the table `menu` */
  11. insert into `menu`(`id`,`pattern`) values
  12. (1,'/db/**'),
  13. (2,'/admin/**'),
  14. (3,'/user/**');
  15. /*Table structure for table `menu_role` */
  16. DROP TABLE IF EXISTS `menu_role`;
  17. CREATE TABLE `menu_role` (
  18. `id` int(11) NOT NULL AUTO_INCREMENT,
  19. `mid` int(11) DEFAULT NULL,
  20. `rid` int(11) DEFAULT NULL,
  21. PRIMARY KEY (`id`)
  22. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
  23. /*Data for the table `menu_role` */
  24. insert into `menu_role`(`id`,`mid`,`rid`) values
  25. (1,1,1),
  26. (2,2,2),
  27. (3,3,3);
  28. /*Table structure for table `role` */
  29. DROP TABLE IF EXISTS `role`;
  30. CREATE TABLE `role` (
  31. `id` int(11) NOT NULL AUTO_INCREMENT,
  32. `name` varchar(32) DEFAULT NULL,
  33. `nameZh` varchar(32) DEFAULT NULL,
  34. PRIMARY KEY (`id`)
  35. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
  36. /*Data for the table `role` */
  37. insert into `role`(`id`,`name`,`nameZh`) values
  38. (1,'ROLE_dba','数据库管理员'),
  39. (2,'ROLE_admin','系统管理员'),
  40. (3,'ROLE_user','用户');
  41. /*Table structure for table `user` */
  42. DROP TABLE IF EXISTS `user`;
  43. CREATE TABLE `user` (
  44. `id` int(11) NOT NULL AUTO_INCREMENT,
  45. `username` varchar(32) DEFAULT NULL,
  46. `password` varchar(255) DEFAULT NULL,
  47. `enabled` tinyint(1) DEFAULT NULL,
  48. `locked` tinyint(1) DEFAULT NULL,
  49. PRIMARY KEY (`id`)
  50. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
  51. /*Data for the table `user` */
  52. insert into `user`(`id`,`username`,`password`,`enabled`,`locked`) values
  53. (1,'root','$2a$10$RMuFXGQ5AtH4wOvkUqyvuecpqUSeoxZYqilXzbz50dceRsga.WYiq',1,0),
  54. (2,'admin','$2a$10$RMuFXGQ5AtH4wOvkUqyvuecpqUSeoxZYqilXzbz50dceRsga.WYiq',1,0),
  55. (3,'sang','$2a$10$RMuFXGQ5AtH4wOvkUqyvuecpqUSeoxZYqilXzbz50dceRsga.WYiq',1,0);
  56. /*Table structure for table `user_role` */
  57. DROP TABLE IF EXISTS `user_role`;
  58. CREATE TABLE `user_role` (
  59. `id` int(11) NOT NULL AUTO_INCREMENT,
  60. `uid` int(11) DEFAULT NULL,
  61. `rid` int(11) DEFAULT NULL,
  62. PRIMARY KEY (`id`)
  63. ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
  64. /*Data for the table `user_role` */
  65. insert into `user_role`(`id`,`uid`,`rid`) values
  66. (1,1,1),
  67. (2,1,2),
  68. (3,2,2),
  69. (4,3,3);

在 application.properties配置数据源

  1. spring.datasource.username=root
  2. spring.datasource.password=root
  3. spring.datasource.url=jdbc:mysql:///security
  4. spring.d
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/922029
推荐阅读
相关标签
  

闽ICP备14008679号