diff --git a/spring-boot-demo-rbac-shiro/pom.xml b/spring-boot-demo-rbac-shiro/pom.xml index 5a9863e..dae3ce8 100644 --- a/spring-boot-demo-rbac-shiro/pom.xml +++ b/spring-boot-demo-rbac-shiro/pom.xml @@ -25,7 +25,18 @@ org.springframework.boot - spring-boot-starter + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework.boot + spring-boot-starter-undertow @@ -33,6 +44,22 @@ spring-boot-starter-test test + + + cn.hutool + hutool-all + + + + com.google.guava + guava + + + + org.projectlombok + lombok + true + diff --git a/spring-boot-demo-rbac-shiro/sql/shiro.sql b/spring-boot-demo-rbac-shiro/sql/shiro.sql new file mode 100644 index 0000000..01b9213 --- /dev/null +++ b/spring-boot-demo-rbac-shiro/sql/shiro.sql @@ -0,0 +1,101 @@ +/* + Navicat Premium Data Transfer + + Source Server : 本机 + Source Server Type : MySQL + Source Server Version : 50718 + Source Host : localhost:3306 + Source Schema : spring-boot-demo + + Target Server Type : MySQL + Target Server Version : 50718 + File Encoding : 65001 + + Date: 12/12/2018 18:52:51 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for sec_user +-- ---------------------------- +DROP TABLE IF EXISTS `shiro_user`; +CREATE TABLE `shiro_user` +( + `id` bigint(64) NOT NULL COMMENT '主键', + `username` varchar(50) NOT NULL COMMENT '用户名', + `password` varchar(60) NOT NULL COMMENT '密码', + `salt` varchar(60) NOT NULL COMMENT '盐值', + `nickname` varchar(255) DEFAULT NULL COMMENT '昵称', + `phone` varchar(11) DEFAULT NULL COMMENT '手机', + `email` varchar(50) DEFAULT NULL COMMENT '邮箱', + `birthday` bigint(13) DEFAULT NULL COMMENT '生日', + `sex` int(2) DEFAULT NULL COMMENT '性别,男-1,女-2', + `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态,启用-1,禁用-0', + `create_time` bigint(13) NOT NULL COMMENT '创建时间', + `update_time` bigint(13) NOT NULL COMMENT '更新时间', + PRIMARY KEY (`id`), + UNIQUE KEY `username` (`username`), + UNIQUE KEY `phone` (`phone`), + UNIQUE KEY `email` (`email`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8 COMMENT ='用户表'; + +-- ---------------------------- +-- Table structure for sec_role +-- ---------------------------- +DROP TABLE IF EXISTS `shiro_role`; +CREATE TABLE `shiro_role` +( + `id` bigint(64) NOT NULL COMMENT '主键', + `name` varchar(50) NOT NULL COMMENT '角色名', + `description` varchar(100) DEFAULT NULL COMMENT '描述', + `create_time` bigint(13) NOT NULL COMMENT '创建时间', + `update_time` bigint(13) NOT NULL COMMENT '更新时间', + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8 COMMENT ='角色表'; + +-- ---------------------------- +-- Table structure for sec_user_role +-- ---------------------------- +DROP TABLE IF EXISTS `shiro_user_role`; +CREATE TABLE `shiro_user_role` +( + `user_id` bigint(64) NOT NULL COMMENT '用户主键', + `role_id` bigint(64) NOT NULL COMMENT '角色主键', + PRIMARY KEY (`user_id`, `role_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8 COMMENT ='用户角色关系表'; + +-- ---------------------------- +-- Table structure for sec_permission +-- ---------------------------- +DROP TABLE IF EXISTS `shiro_permission`; +CREATE TABLE `shiro_permission` +( + `id` bigint(64) NOT NULL COMMENT '主键', + `name` varchar(50) NOT NULL COMMENT '权限名', + `url` varchar(1000) DEFAULT NULL COMMENT '类型为页面时,代表前端路由地址,类型为按钮时,代表后端接口地址', + `type` int(2) NOT NULL COMMENT '权限类型,页面-1,按钮-2', + `permission` varchar(50) DEFAULT NULL COMMENT '权限表达式', + `method` varchar(50) DEFAULT NULL COMMENT '后端接口访问方式', + `sort` int(11) NOT NULL COMMENT '排序', + `parent_id` bigint(64) NOT NULL COMMENT '父级id', + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8 COMMENT ='权限表'; + +-- ---------------------------- +-- Table structure for sec_role_permission +-- ---------------------------- +DROP TABLE IF EXISTS `shiro_role_permission`; +CREATE TABLE `shiro_role_permission` +( + `role_id` bigint(64) NOT NULL COMMENT '角色主键', + `permission_id` bigint(64) NOT NULL COMMENT '权限主键', + PRIMARY KEY (`role_id`, `permission_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8 COMMENT ='角色权限关系表'; \ No newline at end of file diff --git a/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/SpringBootDemoRbacShiroApplication.java b/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/SpringBootDemoRbacShiroApplication.java index 8e137f1..af5add5 100644 --- a/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/SpringBootDemoRbacShiroApplication.java +++ b/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/SpringBootDemoRbacShiroApplication.java @@ -3,6 +3,19 @@ package com.xkcoding.rbac.shiro; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +/** + *

+ * 启动器 + *

+ * + * @package: com.xkcoding.rbac.shiro + * @description: 启动器 + * @author: yangkai.shen + * @date: Created in 2019-03-21 16:11 + * @copyright: Copyright (c) 2019 + * @version: V1.0 + * @modified: yangkai.shen + */ @SpringBootApplication public class SpringBootDemoRbacShiroApplication { diff --git a/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/common/IResultCode.java b/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/common/IResultCode.java new file mode 100644 index 0000000..cadc3c6 --- /dev/null +++ b/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/common/IResultCode.java @@ -0,0 +1,30 @@ +package com.xkcoding.rbac.shiro.common; + +/** + *

+ * 统一状态码接口 + *

+ * + * @package: com.xkcoding.rbac.shiro.common + * @description: 统一状态码接口 + * @author: yangkai.shen + * @date: Created in 2019-03-21 16:28 + * @copyright: Copyright (c) 2019 + * @version: V1.0 + * @modified: yangkai.shen + */ +public interface IResultCode { + /** + * 获取状态码 + * + * @return 状态码 + */ + Integer getCode(); + + /** + * 获取返回消息 + * + * @return 返回消息 + */ + String getMessage(); +} diff --git a/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/common/R.java b/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/common/R.java new file mode 100644 index 0000000..8d5e97a --- /dev/null +++ b/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/common/R.java @@ -0,0 +1,95 @@ +package com.xkcoding.rbac.shiro.common; + +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + *

+ * 统一API对象返回 + *

+ * + * @package: com.xkcoding.rbac.shiro.common + * @description: 统一API对象返回 + * @author: yangkai.shen + * @date: Created in 2019-03-21 16:24 + * @copyright: Copyright (c) 2019 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Data +@NoArgsConstructor +public class R { + /** + * 状态码 + */ + private Integer code; + + /** + * 返回消息 + */ + private String message; + + /** + * 状态 + */ + private boolean status; + + /** + * 返回数据 + */ + private T data; + + public R(Integer code, String message, boolean status, T data) { + this.code = code; + this.message = message; + this.status = status; + this.data = data; + } + + public R(IResultCode resultCode, boolean status, T data) { + this.code = resultCode.getCode(); + this.message = resultCode.getMessage(); + this.status = status; + this.data = data; + } + + public R(IResultCode resultCode, boolean status) { + this.code = resultCode.getCode(); + this.message = resultCode.getMessage(); + this.status = status; + this.data = null; + } + + public static R success() { + return new R<>(ResultCode.OK, true); + } + + public static R message(String message) { + return new R<>(ResultCode.OK.getCode(), message, true, null); + } + + public static R success(T data) { + return new R<>(ResultCode.OK, true, data); + } + + public static R fail() { + return new R<>(ResultCode.ERROR, false); + } + + public static R fail(IResultCode resultCode) { + return new R<>(resultCode, false); + } + + public static R fail(Integer code, String message) { + return new R<>(code, message, false, null); + } + + public static R fail(IResultCode resultCode, T data) { + return new R<>(resultCode, false, data); + } + + public static R fail(Integer code, String message, T data) { + return new R<>(code, message, false, data); + } + +} diff --git a/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/common/ResultCode.java b/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/common/ResultCode.java new file mode 100644 index 0000000..871635e --- /dev/null +++ b/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/common/ResultCode.java @@ -0,0 +1,44 @@ +package com.xkcoding.rbac.shiro.common; + +import lombok.Getter; + +/** + *

+ * 通用状态枚举 + *

+ * + * @package: com.xkcoding.rbac.shiro.common + * @description: 通用状态枚举 + * @author: yangkai.shen + * @date: Created in 2019-03-21 16:31 + * @copyright: Copyright (c) 2019 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Getter +public enum ResultCode implements IResultCode { + /** + * 成功 + */ + OK(200, "成功"), + /** + * 失败 + */ + ERROR(500, "失败"); + + /** + * 返回码 + */ + private Integer code; + + /** + * 返回消息 + */ + private String message; + + ResultCode(Integer code, String message) { + this.code = code; + this.message = message; + } + +} diff --git a/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/controller/TestController.java b/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/controller/TestController.java new file mode 100644 index 0000000..59f6d9c --- /dev/null +++ b/spring-boot-demo-rbac-shiro/src/main/java/com/xkcoding/rbac/shiro/controller/TestController.java @@ -0,0 +1,29 @@ +package com.xkcoding.rbac.shiro.controller; + +import com.xkcoding.rbac.shiro.common.R; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 测试Controller + *

+ * + * @package: com.xkcoding.rbac.shiro.controller + * @description: 测试Controller + * @author: yangkai.shen + * @date: Created in 2019-03-21 16:13 + * @copyright: Copyright (c) 2019 + * @version: V1.0 + * @modified: yangkai.shen + */ +@RestController +@RequestMapping("/test") +public class TestController { + + @GetMapping("") + public R test() { + return R.success(); + } +} diff --git a/spring-boot-demo-rbac-shiro/src/main/resources/application.properties b/spring-boot-demo-rbac-shiro/src/main/resources/application.properties deleted file mode 100644 index e69de29..0000000 diff --git a/spring-boot-demo-rbac-shiro/src/main/resources/application.yml b/spring-boot-demo-rbac-shiro/src/main/resources/application.yml new file mode 100644 index 0000000..a02fbde --- /dev/null +++ b/spring-boot-demo-rbac-shiro/src/main/resources/application.yml @@ -0,0 +1,4 @@ +server: + port: 8080 + servlet: + context-path: /demo \ No newline at end of file