diff --git a/CHANGELOG_TODO.md b/CHANGELOG_TODO.md new file mode 100644 index 00000000..5cb005a9 --- /dev/null +++ b/CHANGELOG_TODO.md @@ -0,0 +1,24 @@ +# CHANGELOG TODO + +## [V1.4] +- 部门树形列表 + +## [V1.5] +- 代码生成起优化,是否生成自定义update方法,生成version,deleted注解 +- 黑白名单,配置文件和数据库可配置,并缓存到Redis +- Redis Cache注解使用 +- ok http工具类 +- Excel解析,导入导出 +- 项目代码遵循阿里代码规范优化 +- 字典表 +- 配置参数表 +- 上传文件附件表 +- Redis分布式锁 +- 接口限流,ip限流,频率限流 +- Shiro Redis缓存 +- ApplicationRunner + + +## [V1.6] +- Spring security集成 +- HikariCP \ No newline at end of file diff --git a/README-zh.md b/README-zh.md index a8f1db9c..d94b79dd 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,6 +1,6 @@

- spring-boot-plus logo + spring-boot-plus logo

@@ -102,45 +102,44 @@ mvn clean package -Plocal ### 1. 创建数据库表 ```sql - -- ---------------------------- --- Table structure for sys_user +-- Table structure for foo_bar -- ---------------------------- -drop table if exists `sys_user`; -create table sys_user +DROP TABLE IF EXISTS `foo_bar`; +CREATE TABLE `foo_bar` ( - id bigint not null comment '主键' - primary key, - username varchar(20) not null comment '用户名', - nickname varchar(20) null comment '昵称', - password varchar(64) not null comment '密码', - salt varchar(32) null comment '盐值', - remark varchar(200) null comment 'remark', - status int default 1 not null comment '状态,0:禁用,1:启用', - create_time timestamp default CURRENT_TIMESTAMP null comment '创建时间', - update_time timestamp null comment '修改时间', - constraint sys_user_username_uindex - unique (username) -) - comment '系统用户'; + `id` bigint(20) NOT NULL COMMENT '主键', + `name` varchar(20) NOT NULL COMMENT '名称', + `foo` varchar(20) DEFAULT NULL COMMENT 'Foo', + `bar` varchar(20) NOT NULL COMMENT 'Bar', + `remark` varchar(200) DEFAULT NULL COMMENT '备注', + `state` int(11) NOT NULL DEFAULT '1' COMMENT '状态,0:禁用,1:启用', + `version` int(11) NOT NULL DEFAULT '0' COMMENT '版本', + `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '修改时间', + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT ='FooBar'; -- ---------------------------- --- Records of sys_user +-- Records of foo_bar -- ---------------------------- -INSERT INTO spring_boot_plus.sys_user (id, username, nickname, password, salt, remark, state, create_time, update_time) - VALUES (1, 'admin', '管理员', '751ade2f90ceb660cb2460f12cc6fe08268e628e4607bdb88a00605b3d66973c', 'e4cc3292e3ebc483998adb2c0e4e640e', 'Administrator Account', 1, '2019-08-26 00:52:01', null); -INSERT INTO spring_boot_plus.sys_user (id, username, nickname, password, salt, remark, state, create_time, update_time) - VALUES (2, 'test', '测试人员', '751ade2f90ceb660cb2460f12cc6fe08268e628e4607bdb88a00605b3d66973c', '99952b31c18156169a26bec80fd211f6', 'Tester Account', 1, '2019-10-05 14:04:27', null); +INSERT INTO foo_bar (id, name, foo, bar, remark, state, version, create_time, update_time) + VALUES (1, 'FooBar', 'foo', 'bar', 'remark...', 1, 0, '2019-11-01 14:05:14', null); +INSERT INTO foo_bar (id, name, foo, bar, remark, state, version, create_time, update_time) + VALUES (2, 'HelloWorld', 'hello', 'world', null, 1, 0, '2019-11-01 14:05:14', null); ``` + ### 2.使用代码生成器生成增删改查代码 > 修改数据库信息 >修改组件名称/作者/数据库表名称/主键id ```text -/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +/src/test/java/io/geekidea/springbootplus/test/SpringBootPlusGenerator.java ``` ```java @@ -169,7 +168,7 @@ public class SpringBootPlusGenerator { // 组件作者等配置 codeGenerator - .setModuleName("system") + .setModuleName("foobar") .setAuthor("geekidea") .setPkIdColumnName("id"); @@ -195,7 +194,7 @@ public class SpringBootPlusGenerator { .setGeneratorMapperXml(true); // 是否生成Shiro RequiresPermissions注解 - codeGenerator.setRequiresPermissions(true); + codeGenerator.setRequiresPermissions(false); // 是否覆盖已有文件 codeGenerator.setFileOverride(true); @@ -206,9 +205,7 @@ public class SpringBootPlusGenerator { // 需要生成的表数组 // xxx,yyy,zzz为需要生成代码的表名称 String[] tables = { - "xxx", - "yyy", - "zzz", + "foo_bar" }; // 循环生成 @@ -227,31 +224,30 @@ public class SpringBootPlusGenerator { > 生成的代码结构 ```text -/src/main/java/io/geekidea/springbootplus/system +/src/main/java/io/geekidea/springbootplus/foobar ``` ```text -└── system +└── foobar + ├── controller + │   └── FooBarController.java ├── entity - │   └── SysUser.java + │   └── FooBar.java ├── mapper - │   └── SysUserMapper.java + │   └── FooBarMapper.java + ├── param + │   └── FooBarQueryParam.java ├── service - │   ├── SysUserService.java + │   ├── FooBarService.java │   └── impl - │   └── SysUserServiceImpl.java - └── web - ├── controller - │   └── SysUserController.java - ├── param - │   └── SysUserQueryParam.java - └── vo - └── SysUserQueryVo.java + │   └── FooBarServiceImpl.java + └── vo + └── FooBarQueryVo.java ``` > Mapper XML ```text -/src/main/resources/mapper/system/SysUserMapper.xml +/src/main/resources/mapper/foobar/FooBarMapper.xml ``` ### 3. 启动项目 @@ -350,6 +346,49 @@ sh deploy.sh tail -f -n 1000 /root/spring-boot-plus-server/logs/spring-boot-plus.log ``` + +## spring-boot-plus Views + +### spring-boot-plus IDEA Sources Views + +![spring-boot-plus-idea](https://spring-boot-plus.gitee.io/img/home/spring-boot-plus-idea.png) + +### [Spring Boot Admin Instances](http://47.105.159.10:8888/instances/e211ba082db8/details) +

+ + spring-boot-admin instances + +

+ +### [Spring Boot Admin Statistics](http://47.105.159.10:8888/instances/e211ba082db8/details) +

+ + spring-boot-admin statistics + +

+ +### [Spring Boot Admin Log](http://47.105.159.10:8888/instances/e211ba082db8/logfile) +

+ + spring-boot-admin log + +

+ +### [spring-boot-plus Swagger文档](http://47.105.159.10:8888/swagger-ui.html) +

+ + spring-boot-plus swagger docs + +

+ +### [spring-boot-plus Java Api Docs](http://geekidea.io/spring-boot-plus-apidocs/) +

+ + spring-boot-plus Java Api Docs + +

+ + ## spring-boot-plus 视频 :movie_camera: - [5分钟完成增删改查](https://www.bilibili.com/video/av67401204) - [CentOS 快速安装 JDK/Git/Maven/Redis/MySQL](https://www.bilibili.com/video/av67218836/) diff --git a/README.md b/README.md index f22d43d6..f1bee8f7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

- spring-boot-plus logo + spring-boot-plus logo

@@ -104,36 +104,33 @@ mvn clean package -Plocal ### 1. Create Table ```sql - -- ---------------------------- --- Table structure for sys_user +-- Table structure for foo_bar -- ---------------------------- -drop table if exists `sys_user`; -create table sys_user +DROP TABLE IF EXISTS `foo_bar`; +CREATE TABLE `foo_bar` ( - id bigint not null comment '' - primary key, - username varchar(20) not null comment '', - nickname varchar(20) null comment '', - password varchar(64) not null comment '', - salt varchar(32) null comment '', - remark varchar(200) null comment '', - status int default 1 not null comment '', - create_time timestamp default CURRENT_TIMESTAMP null comment '', - update_time timestamp null comment '', - constraint sys_user_username_uindex - unique (username) -) - comment 'SysUser'; + `id` bigint(20) NOT NULL COMMENT 'ID', + `name` varchar(20) NOT NULL COMMENT 'Name', + `foo` varchar(20) DEFAULT NULL COMMENT 'Foo', + `bar` varchar(20) NOT NULL COMMENT 'Bar', + `remark` varchar(200) DEFAULT NULL COMMENT 'Remark', + `state` int(11) NOT NULL DEFAULT '1' COMMENT 'State,0:Disable,1:Enable', + `version` int(11) NOT NULL DEFAULT '0' COMMENT 'Version', + `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Create Time', + `update_time` timestamp NULL DEFAULT NULL COMMENT 'Update Time', + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT ='FooBar'; -- ---------------------------- --- Records of sys_user +-- Records of foo_bar -- ---------------------------- -INSERT INTO spring_boot_plus.sys_user (id, username, nickname, password, salt, remark, state, create_time, update_time) - VALUES (1, 'admin', 'Administrators', '751ade2f90ceb660cb2460f12cc6fe08268e628e4607bdb88a00605b3d66973c', 'e4cc3292e3ebc483998adb2c0e4e640e', 'Administrator Account', 1, '2019-08-26 00:52:01', null); - -INSERT INTO spring_boot_plus.sys_user (id, username, nickname, password, salt, remark, state, create_time, update_time) - VALUES (2, 'test', 'Testers', '751ade2f90ceb660cb2460f12cc6fe08268e628e4607bdb88a00605b3d66973c', '99952b31c18156169a26bec80fd211f6', 'Tester Account', 1, '2019-10-05 14:04:27', null); +INSERT INTO foo_bar (id, name, foo, bar, remark, state, version, create_time, update_time) + VALUES (1, 'FooBar', 'foo', 'bar', 'remark...', 1, 0, '2019-11-01 14:05:14', null); +INSERT INTO foo_bar (id, name, foo, bar, remark, state, version, create_time, update_time) + VALUES (2, 'HelloWorld', 'hello', 'world', null, 1, 0, '2019-11-01 14:05:14', null); ``` @@ -143,7 +140,7 @@ INSERT INTO spring_boot_plus.sys_user (id, username, nickname, password, salt, r > Modify module name / author / table name / primary key id ```text -/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +/src/test/java/io/geekidea/springbootplus/test/SpringBootPlusGenerator.java ``` ```java @@ -172,7 +169,7 @@ public class SpringBootPlusGenerator { // Configuration of component author, etc. codeGenerator - .setModuleName("system") + .setModuleName("foobar") .setAuthor("geekidea") .setPkIdColumnName("id"); @@ -197,7 +194,7 @@ public class SpringBootPlusGenerator { .setGeneratorMapperXml(true); // Generated RequiresPermissions Annotation - codeGenerator.setRequiresPermissions(true); + codeGenerator.setRequiresPermissions(false); // Overwrite existing file or not codeGenerator.setFileOverride(true); @@ -207,9 +204,7 @@ public class SpringBootPlusGenerator { // Table array to be generated String[] tables = { - "xxx", - "yyy", - "zzz", + "foo_bar" }; // Cycle generation @@ -228,31 +223,30 @@ public class SpringBootPlusGenerator { > Generated code structure ```text -/src/main/java/io/geekidea/springbootplus/system +/src/main/java/io/geekidea/springbootplus/foobar ``` ```text -└── system +└── foobar + ├── controller + │   └── FooBarController.java ├── entity - │   └── SysUser.java + │   └── FooBar.java ├── mapper - │   └── SysUserMapper.java + │   └── FooBarMapper.java + ├── param + │   └── FooBarQueryParam.java ├── service - │   ├── SysUserService.java + │   ├── FooBarService.java │   └── impl - │   └── SysUserServiceImpl.java - └── web - ├── controller - │   └── SysUserController.java - ├── param - │   └── SysUserQueryParam.java - └── vo - └── SysUserQueryVo.java + │   └── FooBarServiceImpl.java + └── vo + └── FooBarQueryVo.java ``` > Mapper XML ```text -/src/main/resources/mapper/system/SysUserMapper.xml +/src/main/resources/mapper/foobar/FooBarMapper.xml ``` ### 3. Startup Project @@ -355,6 +349,48 @@ tail -f -n 1000 /root/spring-boot-plus-server/logs/spring-boot-plus.log ``` +## spring-boot-plus Views + +### spring-boot-plus IDEA Sources Views + +![spring-boot-plus-idea](https://springboot.plus/img/home/spring-boot-plus-idea.png) + +### [Spring Boot Admin Instances](http://47.105.159.10:8888/instances/e211ba082db8/details) +

+ + spring-boot-admin instances + +

+ +### [Spring Boot Admin Statistics](http://47.105.159.10:8888/instances/e211ba082db8/details) +

+ + spring-boot-admin statistics + +

+ +### [Spring Boot Admin Log](http://47.105.159.10:8888/instances/e211ba082db8/logfile) +

+ + spring-boot-admin log + +

+ +### [spring-boot-plus Swagger文档](http://47.105.159.10:8888/swagger-ui.html) +

+ + spring-boot-plus swagger docs + +

+ +### [spring-boot-plus Java Api Docs](http://geekidea.io/spring-boot-plus-apidocs/) +

+ + spring-boot-plus Java Api Docs + +

+ + ## spring-boot-plus Videos :movie_camera: - [5-Minutes-Finish-CRUD](https://www.bilibili.com/video/av67401204) - [CentOS Quick Installation JDK/Git/Maven/Redis/MySQL](https://www.bilibili.com/video/av67218836/) diff --git a/deploy/deploy.sh b/deploy/deploy.sh index f97ff1db..c6e79506 100644 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -51,8 +51,8 @@ fi pwd # 2. maven打包 -mvn clean -mvn package -Ptest +mvn clean install +mvn clean package -Ptest pwd # 判断是否生成成功 diff --git a/docs/db/mysql_spring_boot_plus.sql b/docs/db/mysql_spring_boot_plus.sql index 9a04d537..e56817dd 100644 --- a/docs/db/mysql_spring_boot_plus.sql +++ b/docs/db/mysql_spring_boot_plus.sql @@ -65,6 +65,35 @@ INSERT INTO `sys_log` VALUES (1060438799600861185, 0, 'C', 100000, '2018-11-08 1 INSERT INTO `sys_log` VALUES (1060438809495224322, 0, 'D', 100000, '2018-11-08 15:42:13'); +-- ---------------------------- +-- Table structure for foo_bar +-- ---------------------------- +DROP TABLE IF EXISTS `foo_bar`; +CREATE TABLE `foo_bar` +( + `id` bigint(20) NOT NULL COMMENT '主键', + `name` varchar(20) NOT NULL COMMENT '名称', + `foo` varchar(20) DEFAULT NULL COMMENT 'Foo', + `bar` varchar(20) NOT NULL COMMENT 'Bar', + `remark` varchar(200) DEFAULT NULL COMMENT '备注', + `state` int(11) NOT NULL DEFAULT '1' COMMENT '状态,0:禁用,1:启用', + `version` int(11) NOT NULL DEFAULT '0' COMMENT '版本', + `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '修改时间', + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT ='FooBar'; + +-- ---------------------------- +-- Records of foo_bar +-- ---------------------------- +INSERT INTO foo_bar (id, name, foo, bar, remark, state, version, create_time, update_time) +VALUES (1, 'FooBar', 'foo', 'bar', 'remark...', 1, 0, '2019-11-01 14:05:14', null); +INSERT INTO foo_bar (id, name, foo, bar, remark, state, version, create_time, update_time) +VALUES (2, 'HelloWorld', 'hello', 'world', null, 1, 0, '2019-11-01 14:05:14', null); + + -- ---------------------------- -- Table structure for sys_department -- ---------------------------- @@ -74,6 +103,7 @@ CREATE TABLE `sys_department` `id` bigint(20) NOT NULL COMMENT '主键', `name` varchar(32) NOT NULL COMMENT '部门名称', `parent_id` bigint(20) DEFAULT NULL COMMENT '父id', + `level` int NULL COMMENT '部门层级', `state` int(11) NOT NULL DEFAULT '1' COMMENT '状态,0:禁用,1:启用', `sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序', `remark` varchar(200) DEFAULT NULL COMMENT '备注', @@ -89,8 +119,17 @@ CREATE TABLE `sys_department` -- ---------------------------- -- Records of sys_department -- ---------------------------- -INSERT INTO sys_department (id, name, parent_id, state, sort, remark, version, create_time, update_time) VALUES (1, '管理部', null, 1, 0, null, 0, '2019-10-25 09:46:49', null); -INSERT INTO sys_department (id, name, parent_id, state, sort, remark, version, create_time, update_time) VALUES (2, '测试部', null, 1, 0, null, 0, '2019-10-25 09:47:06', null); +INSERT INTO sys_department (id, name, parent_id, level, state, sort, remark, version, create_time, update_time) VALUES (1, '管理部', null, 1, 1, 0, null, 0, '2019-10-25 09:46:49', null); +INSERT INTO sys_department (id, name, parent_id, level, state, sort, remark, version, create_time, update_time) VALUES (2, '技术部', null, 1, 1, 0, null, 0, '2019-11-01 20:45:43', null); +INSERT INTO sys_department (id, name, parent_id, level, state, sort, remark, version, create_time, update_time) VALUES (20, '前端开发部', 2, 2, 1, 0, null, 0, '2019-11-01 20:48:38', null); +INSERT INTO sys_department (id, name, parent_id, level, state, sort, remark, version, create_time, update_time) VALUES (21, '后台开发部', 2, 2, 1, 0, null, 0, '2019-11-01 20:48:38', null); +INSERT INTO sys_department (id, name, parent_id, level, state, sort, remark, version, create_time, update_time) VALUES (22, '测试部', 2, 2, 1, 0, null, 0, '2019-11-01 20:48:38', null); +INSERT INTO sys_department (id, name, parent_id, level, state, sort, remark, version, create_time, update_time) VALUES (201, '前端一组', 20, 3, 1, 0, null, 0, '2019-11-01 20:48:38', null); +INSERT INTO sys_department (id, name, parent_id, level, state, sort, remark, version, create_time, update_time) VALUES (202, '前端二组', 20, 3, 1, 0, null, 0, '2019-11-01 20:48:38', null); +INSERT INTO sys_department (id, name, parent_id, level, state, sort, remark, version, create_time, update_time) VALUES (203, '后台一组', 21, 3, 1, 0, null, 0, '2019-11-01 20:48:38', null); +INSERT INTO sys_department (id, name, parent_id, level, state, sort, remark, version, create_time, update_time) VALUES (204, '后台二组', 21, 3, 1, 0, null, 0, '2019-11-01 20:48:38', null); +INSERT INTO sys_department (id, name, parent_id, level, state, sort, remark, version, create_time, update_time) VALUES (205, '测试一组', 22, 3, 1, 0, null, 0, '2019-11-01 20:48:38', null); + -- ---------------------------- -- Table structure for sys_user @@ -271,7 +310,6 @@ INSERT INTO sys_role_permission (id, role_id, permission_id, state, remark, vers INSERT INTO sys_role_permission (id, role_id, permission_id, state, remark, version, create_time, update_time) VALUES (29, 1, 4002, 1, null, 0, '2019-10-26 22:16:19', null); INSERT INTO sys_role_permission (id, role_id, permission_id, state, remark, version, create_time, update_time) VALUES (30, 1, 4003, 1, null, 0, '2019-10-26 22:16:19', null); INSERT INTO sys_role_permission (id, role_id, permission_id, state, remark, version, create_time, update_time) VALUES (31, 1, 4004, 1, null, 0, '2019-10-26 22:16:19', null); -INSERT INTO sys_role_permission (id, role_id, permission_id, state, remark, version, create_time, update_time) VALUES (32, 1, 4005, 1, null, 0, '2019-10-26 22:16:19', null); INSERT INTO sys_role_permission (id, role_id, permission_id, state, remark, version, create_time, update_time) VALUES (100, 1, 1, 1, null, 0, '2019-10-26 22:16:19', null); INSERT INTO sys_role_permission (id, role_id, permission_id, state, remark, version, create_time, update_time) VALUES (101, 1, 100, 1, null, 0, '2019-10-26 22:16:19', null); INSERT INTO sys_role_permission (id, role_id, permission_id, state, remark, version, create_time, update_time) VALUES (102, 1, 1000, 1, null, 0, '2019-10-26 22:16:19', null); diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java b/src/main/java/io/geekidea/springbootplus/common/xss/XssFilter.java similarity index 97% rename from src/main/java/io/geekidea/springbootplus/xss/XssFilter.java rename to src/main/java/io/geekidea/springbootplus/common/xss/XssFilter.java index c219dd42..fe0fc633 100644 --- a/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java +++ b/src/main/java/io/geekidea/springbootplus/common/xss/XssFilter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.xss; +package io.geekidea.springbootplus.common.xss; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java b/src/main/java/io/geekidea/springbootplus/common/xss/XssHttpServletRequestWrapper.java similarity index 97% rename from src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java rename to src/main/java/io/geekidea/springbootplus/common/xss/XssHttpServletRequestWrapper.java index 8a91ccd0..bf0d11e1 100644 --- a/src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java +++ b/src/main/java/io/geekidea/springbootplus/common/xss/XssHttpServletRequestWrapper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.xss; +package io.geekidea.springbootplus.common.xss; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.text.StringEscapeUtils; diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java b/src/main/java/io/geekidea/springbootplus/common/xss/XssJacksonDeserializer.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java rename to src/main/java/io/geekidea/springbootplus/common/xss/XssJacksonDeserializer.java index d612dbdb..27a76323 100644 --- a/src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java +++ b/src/main/java/io/geekidea/springbootplus/common/xss/XssJacksonDeserializer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.xss; +package io.geekidea.springbootplus.common.xss; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.java b/src/main/java/io/geekidea/springbootplus/common/xss/XssJacksonSerializer.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.java rename to src/main/java/io/geekidea/springbootplus/common/xss/XssJacksonSerializer.java index 71bdbde8..1bb11381 100644 --- a/src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.java +++ b/src/main/java/io/geekidea/springbootplus/common/xss/XssJacksonSerializer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.xss; +package io.geekidea.springbootplus.common.xss; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; diff --git a/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java b/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java index 0a9e4908..2f4dbe53 100644 --- a/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java +++ b/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java @@ -34,8 +34,8 @@ import io.geekidea.springbootplus.config.json.jackson.serializer.JacksonDateSerializer; import io.geekidea.springbootplus.config.json.jackson.serializer.JacksonIntegerDeserializer; import io.geekidea.springbootplus.constant.DatePattern; -import io.geekidea.springbootplus.xss.XssJacksonDeserializer; -import io.geekidea.springbootplus.xss.XssJacksonSerializer; +import io.geekidea.springbootplus.common.xss.XssJacksonDeserializer; +import io.geekidea.springbootplus.common.xss.XssJacksonSerializer; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; diff --git a/src/main/java/io/geekidea/springbootplus/core/aop/AbstractLogAop.java b/src/main/java/io/geekidea/springbootplus/core/aop/AbstractLogAop.java index a52a1584..52e31608 100644 --- a/src/main/java/io/geekidea/springbootplus/core/aop/AbstractLogAop.java +++ b/src/main/java/io/geekidea/springbootplus/core/aop/AbstractLogAop.java @@ -16,7 +16,6 @@ package io.geekidea.springbootplus.core.aop; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import io.geekidea.springbootplus.common.api.ApiCode; import io.geekidea.springbootplus.common.api.ApiResult; @@ -25,6 +24,7 @@ import io.geekidea.springbootplus.util.AnsiUtil; import io.geekidea.springbootplus.util.DateUtil; import io.geekidea.springbootplus.util.IpUtil; +import io.geekidea.springbootplus.util.Jackson; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ArrayUtils; @@ -294,9 +294,9 @@ protected String formatRequestInfo(Map map) { String requestInfo = null; try { if (logAopConfig.isRequestLogFormat()) { - requestInfo = "\n" + JSON.toJSONString(map, true); + requestInfo = "\n" + Jackson.toJsonString(map, true); } else { - requestInfo = JSON.toJSONString(map); + requestInfo = Jackson.toJsonString(map); } } catch (Exception e) { e.printStackTrace(); @@ -323,9 +323,9 @@ protected String formatResponseInfo(ApiResult apiResult) { String responseResultInfo = "responseResult:"; try { if (logAopConfig.isResponseLogFormat()) { - responseResultInfo += "\n" + JSON.toJSONString(apiResult, true); + responseResultInfo += "\n" + Jackson.toJsonString(apiResult, true); } else { - responseResultInfo += JSON.toJSONString(apiResult); + responseResultInfo += Jackson.toJsonString(apiResult); } int code = apiResult.getCode(); if (code == ApiCode.SUCCESS.getCode()) { diff --git a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java index a3b07174..b265725f 100644 --- a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java @@ -16,13 +16,8 @@ package io.geekidea.springbootplus.core.config; import io.geekidea.springbootplus.core.properties.*; -import io.geekidea.springbootplus.interceptor.PermissionInterceptor; -import io.geekidea.springbootplus.resource.interceptor.DownloadInterceptor; -import io.geekidea.springbootplus.resource.interceptor.ResourceInterceptor; -import io.geekidea.springbootplus.resource.interceptor.UploadInterceptor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** @@ -43,47 +38,4 @@ }) public class SpringBootPlusConfig { - /** - * 权限拦截器 - * - * @return - */ - @Bean - public PermissionInterceptor permissionInterceptor() { - PermissionInterceptor permissionInterceptor = new PermissionInterceptor(); - return permissionInterceptor; - } - - /** - * 上传拦截器 - * - * @return - */ - @Bean - public UploadInterceptor uploadInterceptor() { - UploadInterceptor uploadInterceptor = new UploadInterceptor(); - return uploadInterceptor; - } - - /** - * 资源拦截器 - * - * @return - */ - @Bean - public ResourceInterceptor resourceInterceptor() { - ResourceInterceptor resourceInterceptor = new ResourceInterceptor(); - return resourceInterceptor; - } - - /** - * 下载拦截器 - * - * @return - */ - @Bean - public DownloadInterceptor downloadInterceptor() { - DownloadInterceptor downloadInterceptor = new DownloadInterceptor(); - return downloadInterceptor; - } } diff --git a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java index 1c249b76..f565f61c 100644 --- a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java @@ -17,9 +17,9 @@ package io.geekidea.springbootplus.core.config; import com.alibaba.fastjson.JSON; -import io.geekidea.springbootplus.interceptor.PermissionInterceptor; import io.geekidea.springbootplus.core.properties.SpringBootPlusInterceptorProperties; import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; +import io.geekidea.springbootplus.interceptor.PermissionInterceptor; import io.geekidea.springbootplus.resource.interceptor.DownloadInterceptor; import io.geekidea.springbootplus.resource.interceptor.ResourceInterceptor; import io.geekidea.springbootplus.resource.interceptor.UploadInterceptor; @@ -27,6 +27,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; @@ -44,20 +45,56 @@ @Configuration public class SpringBootPlusWebMvcConfig implements WebMvcConfigurer { + /** + * spring-boot-plus配置属性 + */ @Autowired private SpringBootPlusProperties springBootPlusProperties; - @Autowired - private PermissionInterceptor permissionInterceptor; + /** + * 权限拦截器 + * + * @return + */ + @Bean + public PermissionInterceptor permissionInterceptor() { + PermissionInterceptor permissionInterceptor = new PermissionInterceptor(); + return permissionInterceptor; + } - @Autowired - private ResourceInterceptor resourceInterceptor; + /** + * 上传拦截器 + * + * @return + */ + @Bean + public UploadInterceptor uploadInterceptor() { + UploadInterceptor uploadInterceptor = new UploadInterceptor(); + return uploadInterceptor; + } - @Autowired - private UploadInterceptor uploadInterceptor; + /** + * 资源拦截器 + * + * @return + */ + @Bean + public ResourceInterceptor resourceInterceptor() { + ResourceInterceptor resourceInterceptor = new ResourceInterceptor(); + return resourceInterceptor; + } + + /** + * 下载拦截器 + * + * @return + */ + @Bean + public DownloadInterceptor downloadInterceptor() { + DownloadInterceptor downloadInterceptor = new DownloadInterceptor(); + return downloadInterceptor; + } - @Autowired - private DownloadInterceptor downloadInterceptor; @PostConstruct public void init(){ @@ -71,25 +108,25 @@ public void addInterceptors(InterceptorRegistry registry) { // 上传拦截器 if (interceptorConfig.getUpload().isEnabled()){ - registry.addInterceptor(uploadInterceptor) + registry.addInterceptor(uploadInterceptor()) .addPathPatterns(interceptorConfig.getUpload().getIncludePaths()); } // 资源拦截器注册 if (interceptorConfig.getResource().isEnabled()){ - registry.addInterceptor(resourceInterceptor) + registry.addInterceptor(resourceInterceptor()) .addPathPatterns(interceptorConfig.getResource().getIncludePaths()); } // 下载拦截器注册 if (interceptorConfig.getDownload().isEnabled()){ - registry.addInterceptor(downloadInterceptor) + registry.addInterceptor(downloadInterceptor()) .addPathPatterns(interceptorConfig.getDownload().getIncludePaths()); } if (interceptorConfig.getPermission().isEnabled()){ // 权限拦截器注册 - registry.addInterceptor(permissionInterceptor) + registry.addInterceptor(permissionInterceptor()) .addPathPatterns(interceptorConfig.getPermission().getIncludePaths()) .excludePathPatterns(interceptorConfig.getPermission().getExcludePaths()); } diff --git a/src/main/java/io/geekidea/springbootplus/foobar/controller/FooBarController.java b/src/main/java/io/geekidea/springbootplus/foobar/controller/FooBarController.java new file mode 100644 index 00000000..110f1886 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/foobar/controller/FooBarController.java @@ -0,0 +1,90 @@ +package io.geekidea.springbootplus.foobar.controller; + +import io.geekidea.springbootplus.foobar.entity.FooBar; +import io.geekidea.springbootplus.foobar.service.FooBarService; +import io.geekidea.springbootplus.foobar.param.FooBarQueryParam; +import io.geekidea.springbootplus.foobar.vo.FooBarQueryVo; +import io.geekidea.springbootplus.common.api.ApiResult; +import io.geekidea.springbootplus.common.controller.BaseController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + + +import javax.validation.Valid; + +import io.geekidea.springbootplus.common.vo.Paging; +import io.geekidea.springbootplus.common.param.IdParam; + +/** + *
+ * FooBar 前端控制器
+ * 
+ * + * @author geekidea + * @since 2019-11-01 + */ +@Slf4j +@RestController +@RequestMapping("/fooBar") +@Api("FooBar API") +public class FooBarController extends BaseController { + + @Autowired + private FooBarService fooBarService; + + /** + * 添加FooBar + */ + @PostMapping("/add") + @ApiOperation(value = "添加FooBar对象", notes = "添加FooBar", response = ApiResult.class) + public ApiResult addFooBar(@Valid @RequestBody FooBar fooBar) throws Exception { + boolean flag = fooBarService.saveFooBar(fooBar); + return ApiResult.result(flag); + } + + /** + * 修改FooBar + */ + @PostMapping("/update") + @ApiOperation(value = "修改FooBar对象", notes = "修改FooBar", response = ApiResult.class) + public ApiResult updateFooBar(@Valid @RequestBody FooBar fooBar) throws Exception { + boolean flag = fooBarService.updateFooBar(fooBar); + return ApiResult.result(flag); + } + + /** + * 删除FooBar + */ + @PostMapping("/delete/{id}") + @ApiOperation(value = "删除FooBar对象", notes = "删除FooBar", response = ApiResult.class) + public ApiResult deleteFooBar(@PathVariable("id") Long id) throws Exception { + boolean flag = fooBarService.deleteFooBar(id); + return ApiResult.result(flag); + } + + /** + * 获取FooBar + */ + @GetMapping("/info/{id}") + @ApiOperation(value = "获取FooBar对象详情", notes = "查看FooBar", response = FooBarQueryVo.class) + public ApiResult getFooBar(@PathVariable("id") Long id) throws Exception { + FooBarQueryVo fooBarQueryVo = fooBarService.getFooBarById(id); + return ApiResult.ok(fooBarQueryVo); + } + + /** + * FooBar分页列表 + */ + @PostMapping("/getPageList") + @ApiOperation(value = "获取FooBar分页列表", notes = "FooBar分页列表", response = FooBarQueryVo.class) + public ApiResult> getFooBarPageList(@Valid @RequestBody FooBarQueryParam fooBarQueryParam) throws Exception { + Paging paging = fooBarService.getFooBarPageList(fooBarQueryParam); + return ApiResult.ok(paging); + } + +} + diff --git a/src/main/java/io/geekidea/springbootplus/foobar/entity/FooBar.java b/src/main/java/io/geekidea/springbootplus/foobar/entity/FooBar.java new file mode 100644 index 00000000..268fe32e --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/foobar/entity/FooBar.java @@ -0,0 +1,62 @@ +package io.geekidea.springbootplus.foobar.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import java.util.Date; +import com.baomidou.mybatisplus.annotation.TableId; +import io.geekidea.springbootplus.common.entity.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + *
+ * FooBar
+ * 
+ * + * @author geekidea + * @since 2019-11-01 + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "FooBar对象", description = "FooBar") +public class FooBar extends BaseEntity { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "ID") + @TableId(value = "id", type = IdType.ID_WORKER) + private Long id; + + @ApiModelProperty(value = "Name") + @NotBlank(message = "Name不能为空") + private String name; + + @ApiModelProperty(value = "Foo") + private String foo; + + @ApiModelProperty(value = "Bar") + @NotBlank(message = "Bar不能为空") + private String bar; + + @ApiModelProperty(value = "Remark") + private String remark; + + @ApiModelProperty(value = "State,0:Disable,1:Enable") + private Integer state; + + @ApiModelProperty(value = "Version") + private Integer version; + + @ApiModelProperty(value = "Create Time") + private Date createTime; + + @ApiModelProperty(value = "Update Time") + private Date updateTime; + +} diff --git a/src/main/java/io/geekidea/springbootplus/foobar/mapper/FooBarMapper.java b/src/main/java/io/geekidea/springbootplus/foobar/mapper/FooBarMapper.java new file mode 100644 index 00000000..b9fccc82 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/foobar/mapper/FooBarMapper.java @@ -0,0 +1,42 @@ +package io.geekidea.springbootplus.foobar.mapper; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.geekidea.springbootplus.foobar.entity.FooBar; +import io.geekidea.springbootplus.foobar.param.FooBarQueryParam; +import io.geekidea.springbootplus.foobar.vo.FooBarQueryVo; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.io.Serializable; + +/** + *
+ * FooBar Mapper 接口
+ * 
+ * + * @author geekidea + * @since 2019-11-01 + */ +@Repository +public interface FooBarMapper extends BaseMapper { + + /** + * 根据ID获取查询对象 + * + * @param id + * @return + */ + FooBarQueryVo getFooBarById(Serializable id); + + /** + * 获取分页对象 + * + * @param page + * @param fooBarQueryParam + * @return + */ + IPage getFooBarPageList(@Param("page") Page page, @Param("param") FooBarQueryParam fooBarQueryParam); + +} diff --git a/src/main/java/io/geekidea/springbootplus/foobar/param/FooBarQueryParam.java b/src/main/java/io/geekidea/springbootplus/foobar/param/FooBarQueryParam.java new file mode 100644 index 00000000..bc23f13e --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/foobar/param/FooBarQueryParam.java @@ -0,0 +1,24 @@ +package io.geekidea.springbootplus.foobar.param; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import io.geekidea.springbootplus.common.param.OrderQueryParam; + +/** + *
+ * FooBar 查询参数对象
+ * 
+ * + * @author geekidea + * @date 2019-11-01 + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "FooBarQueryParam对象", description = "FooBar查询参数") +public class FooBarQueryParam extends OrderQueryParam { + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/io/geekidea/springbootplus/foobar/service/FooBarService.java b/src/main/java/io/geekidea/springbootplus/foobar/service/FooBarService.java new file mode 100644 index 00000000..90149571 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/foobar/service/FooBarService.java @@ -0,0 +1,66 @@ +package io.geekidea.springbootplus.foobar.service; + +import io.geekidea.springbootplus.foobar.entity.FooBar; +import io.geekidea.springbootplus.common.service.BaseService; +import io.geekidea.springbootplus.foobar.param.FooBarQueryParam; +import io.geekidea.springbootplus.foobar.vo.FooBarQueryVo; +import io.geekidea.springbootplus.common.vo.Paging; + +import java.io.Serializable; + +/** + *
+ * FooBar 服务类
+ * 
+ * + * @author geekidea + * @since 2019-11-01 + */ +public interface FooBarService extends BaseService { + + /** + * 保存 + * + * @param fooBar + * @return + * @throws Exception + */ + boolean saveFooBar(FooBar fooBar) throws Exception; + + /** + * 修改 + * + * @param fooBar + * @return + * @throws Exception + */ + boolean updateFooBar(FooBar fooBar) throws Exception; + + /** + * 删除 + * + * @param id + * @return + * @throws Exception + */ + boolean deleteFooBar(Long id) throws Exception; + + /** + * 根据ID获取查询对象 + * + * @param id + * @return + * @throws Exception + */ + FooBarQueryVo getFooBarById(Serializable id) throws Exception; + + /** + * 获取分页对象 + * + * @param fooBarQueryParam + * @return + * @throws Exception + */ + Paging getFooBarPageList(FooBarQueryParam fooBarQueryParam) throws Exception; + +} diff --git a/src/main/java/io/geekidea/springbootplus/foobar/service/impl/FooBarServiceImpl.java b/src/main/java/io/geekidea/springbootplus/foobar/service/impl/FooBarServiceImpl.java new file mode 100644 index 00000000..345e02a0 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/foobar/service/impl/FooBarServiceImpl.java @@ -0,0 +1,67 @@ +package io.geekidea.springbootplus.foobar.service.impl; + +import io.geekidea.springbootplus.foobar.entity.FooBar; +import io.geekidea.springbootplus.foobar.mapper.FooBarMapper; +import io.geekidea.springbootplus.foobar.service.FooBarService; +import io.geekidea.springbootplus.foobar.param.FooBarQueryParam; +import io.geekidea.springbootplus.foobar.vo.FooBarQueryVo; +import io.geekidea.springbootplus.common.service.impl.BaseServiceImpl; +import io.geekidea.springbootplus.common.vo.Paging; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.beans.factory.annotation.Autowired; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +import java.io.Serializable; + + +/** + *
+ * FooBar 服务实现类
+ * 
+ * + * @author geekidea + * @since 2019-11-01 + */ +@Slf4j +@Service +public class FooBarServiceImpl extends BaseServiceImpl implements FooBarService { + + @Autowired + private FooBarMapper fooBarMapper; + + @Transactional(rollbackFor = Exception.class) + @Override + public boolean saveFooBar(FooBar fooBar) throws Exception { + return super.save(fooBar); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public boolean updateFooBar(FooBar fooBar) throws Exception { + return super.updateById(fooBar); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public boolean deleteFooBar(Long id) throws Exception { + return super.removeById(id); + } + + @Override + public FooBarQueryVo getFooBarById(Serializable id) throws Exception { + return fooBarMapper.getFooBarById(id); + } + + @Override + public Paging getFooBarPageList(FooBarQueryParam fooBarQueryParam) throws Exception { + Page page = setPageParam(fooBarQueryParam, OrderItem.desc("create_time")); + IPage iPage = fooBarMapper.getFooBarPageList(page, fooBarQueryParam); + return new Paging(iPage); + } + +} diff --git a/src/main/java/io/geekidea/springbootplus/foobar/vo/FooBarQueryVo.java b/src/main/java/io/geekidea/springbootplus/foobar/vo/FooBarQueryVo.java new file mode 100644 index 00000000..1581d9a2 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/foobar/vo/FooBarQueryVo.java @@ -0,0 +1,52 @@ +package io.geekidea.springbootplus.foobar.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; +import java.io.Serializable; + +import java.util.Date; + +/** + *
+ * FooBar 查询结果对象
+ * 
+ * + * @author geekidea + * @date 2019-11-01 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "FooBarQueryVo对象", description = "FooBar查询参数") +public class FooBarQueryVo implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "ID") + private Long id; + + @ApiModelProperty(value = "Name") + private String name; + + @ApiModelProperty(value = "Foo") + private String foo; + + @ApiModelProperty(value = "Bar") + private String bar; + + @ApiModelProperty(value = "Remark") + private String remark; + + @ApiModelProperty(value = "State,0:Disable,1:Enable") + private Integer state; + + @ApiModelProperty(value = "Version") + private Integer version; + + @ApiModelProperty(value = "Create Time") + private Date createTime; + + @ApiModelProperty(value = "Update Time") + private Date updateTime; + +} \ No newline at end of file diff --git a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java index ffa7297b..bd373caf 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java @@ -46,7 +46,6 @@ import org.apache.shiro.spring.web.ShiroFilterFactoryBean; import org.apache.shiro.web.mgt.DefaultWebSecurityManager; import org.apache.shiro.web.mgt.DefaultWebSessionStorageEvaluator; -import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; @@ -253,9 +252,9 @@ private Map addDefaultFilterDefinition(Map filte } else { String[] strings = value.split(","); List list = new ArrayList<>(); - list.addAll(Arrays.asList(strings)); // 添加默认filter过滤 list.add(REQUEST_PATH_FILTER_NAME); + list.addAll(Arrays.asList(strings)); definition = String.join(",", list); } map.put(key, definition); @@ -300,18 +299,6 @@ public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() { return new LifecycleBeanPostProcessor(); } - /** - * depends-on lifecycleBeanPostProcessor - * - * @return - */ - @Bean - public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { - DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator(); - defaultAdvisorAutoProxyCreator.setProxyTargetClass(true); - return defaultAdvisorAutoProxyCreator; - } - @Bean public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) { AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor(); diff --git a/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtRealm.java b/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtRealm.java index 25c6f710..35d9202d 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtRealm.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtRealm.java @@ -59,7 +59,6 @@ public boolean supports(AuthenticationToken token) { */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { - // TODO 被调用两次 log.debug("doGetAuthorizationInfo principalCollection..."); // 设置角色/权限信息 JwtToken jwtToken = (JwtToken) principalCollection.getPrimaryPrincipal(); diff --git a/src/main/java/io/geekidea/springbootplus/system/controller/SysDepartmentController.java b/src/main/java/io/geekidea/springbootplus/system/controller/SysDepartmentController.java index 600deea7..a8f4c2e3 100644 --- a/src/main/java/io/geekidea/springbootplus/system/controller/SysDepartmentController.java +++ b/src/main/java/io/geekidea/springbootplus/system/controller/SysDepartmentController.java @@ -23,15 +23,16 @@ import io.geekidea.springbootplus.system.param.SysDepartmentQueryParam; import io.geekidea.springbootplus.system.service.SysDepartmentService; import io.geekidea.springbootplus.system.vo.SysDepartmentQueryVo; +import io.geekidea.springbootplus.system.vo.SysDepartmentTreeVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import java.util.List; /** *
@@ -105,5 +106,27 @@ public ApiResult> getSysDepartmentPageList(@Valid @
         return ApiResult.ok(paging);
     }
 
+    /**
+     * 获取所有部门列表
+     */
+    @PostMapping("/getAllDepartmentList")
+//    @RequiresPermissions("sys:department:all:list")
+    @ApiOperation(value = "获取所有部门的树形列表", notes = "获取所有部门的树形列表", response = SysDepartment.class)
+    public ApiResult> getAllDepartmentList() throws Exception {
+        List list = sysDepartmentService.getAllDepartmentList();
+        return ApiResult.ok(list);
+    }
+
+    /**
+     * 获取所有部门的树形列表
+     */
+    @PostMapping("/getAllDepartmentTree")
+//    @RequiresPermissions("sys:department:all:tree")
+    @ApiOperation(value = "获取所有部门的树形列表", notes = "获取所有部门的树形列表", response = SysDepartmentTreeVo.class)
+    public ApiResult> getAllDepartmentTree() throws Exception {
+        List treeVos = sysDepartmentService.getAllDepartmentTree();
+        return ApiResult.ok(treeVos);
+    }
+
 }
 
diff --git a/src/main/java/io/geekidea/springbootplus/system/controller/SysPermissionController.java b/src/main/java/io/geekidea/springbootplus/system/controller/SysPermissionController.java
index 4dc584af..3a9ce856 100644
--- a/src/main/java/io/geekidea/springbootplus/system/controller/SysPermissionController.java
+++ b/src/main/java/io/geekidea/springbootplus/system/controller/SysPermissionController.java
@@ -124,8 +124,8 @@ public ApiResult getAllMenuList() throws Exception {
     @RequiresPermissions("sys:permission:all:menu:tree")
     @ApiOperation(value = "获取所有菜单列表", notes = "获取所有菜单列表", response = SysPermissionTreeVo.class)
     public ApiResult getAllMenuTree() throws Exception {
-        List list = sysPermissionService.getAllMenuTree();
-        return ApiResult.ok(list);
+        List treeVos = sysPermissionService.getAllMenuTree();
+        return ApiResult.ok(treeVos);
     }
 
 
@@ -147,8 +147,8 @@ public ApiResult getMenuListByUserId(@PathVariable("userId") Long
     @RequiresPermissions("sys:permission:menu:tree")
     @ApiOperation(value = "根据用户id获取菜单树形列表", notes = "根据用户id获取菜单树形列表", response = SysPermissionTreeVo.class)
     public ApiResult getMenuTreeByUserId(@PathVariable("userId") Long userId) throws Exception {
-        List list = sysPermissionService.getMenuTreeByUserId(userId);
-        return ApiResult.ok(list);
+        List treeVos = sysPermissionService.getMenuTreeByUserId(userId);
+        return ApiResult.ok(treeVos);
     }
 
     /**
diff --git a/src/main/java/io/geekidea/springbootplus/system/controller/VerificationCodeController.java b/src/main/java/io/geekidea/springbootplus/system/controller/VerificationCodeController.java
index 3ed74459..5d233a80 100644
--- a/src/main/java/io/geekidea/springbootplus/system/controller/VerificationCodeController.java
+++ b/src/main/java/io/geekidea/springbootplus/system/controller/VerificationCodeController.java
@@ -24,7 +24,6 @@
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.http.MediaType;
@@ -60,7 +59,6 @@ public class VerificationCodeController {
      * 获取验证码
      */
     @GetMapping("/getImage")
-    @RequiresPermissions("verification:code")
     @ApiOperation(value = "获取验证码", notes = "获取验证码", response = ApiResult.class)
     public void getImage(HttpServletResponse response) throws Exception {
         VerificationCode verificationCode = new VerificationCode();
@@ -68,7 +66,7 @@ public void getImage(HttpServletResponse response) throws Exception {
         String code = verificationCode.getText();
         String verifyToken = UUIDUtil.getUUID();
         // 缓存到Redis
-        redisTemplate.opsForValue().set(String.format(CommonRedisKey.VERIFY_CODE, verifyToken), code, 10, TimeUnit.MINUTES);
+        redisTemplate.opsForValue().set(String.format(CommonRedisKey.VERIFY_CODE, verifyToken), code, 5, TimeUnit.MINUTES);
         response.setHeader(CommonConstant.VERIFY_TOKEN, verifyToken);
         response.setContentType(MediaType.IMAGE_JPEG_VALUE);
         response.setHeader("Pragma", "No-cache");
@@ -82,7 +80,6 @@ public void getImage(HttpServletResponse response) throws Exception {
      * 获取图片Base64验证码
      */
     @GetMapping("/getBase64Image")
-    @RequiresPermissions("verification:code")
     @ResponseBody
     @ApiOperation(value = "获取图片Base64验证码", notes = "获取图片Base64验证码", response = ApiResult.class)
     public ApiResult getCode(HttpServletResponse response) throws Exception {
@@ -99,7 +96,7 @@ public ApiResult getCode(HttpServletResponse response) throws Exception {
         map.put(CommonConstant.IMAGE, CommonConstant.BASE64_PREFIX + base64);
         map.put(CommonConstant.VERIFY_TOKEN, verifyToken);
         // 缓存到Redis
-        redisTemplate.opsForValue().set(String.format(CommonRedisKey.VERIFY_CODE, verifyToken), code, 10, TimeUnit.MINUTES);
+        redisTemplate.opsForValue().set(String.format(CommonRedisKey.VERIFY_CODE, verifyToken), code, 5, TimeUnit.MINUTES);
         return ApiResult.ok(map);
     }
 
diff --git a/src/main/java/io/geekidea/springbootplus/system/convert/SysDepartmentConvert.java b/src/main/java/io/geekidea/springbootplus/system/convert/SysDepartmentConvert.java
new file mode 100644
index 00000000..78e46e9d
--- /dev/null
+++ b/src/main/java/io/geekidea/springbootplus/system/convert/SysDepartmentConvert.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2019-2029 geekidea(https://github.com/geekidea)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.geekidea.springbootplus.system.convert;
+
+import io.geekidea.springbootplus.system.entity.SysDepartment;
+import io.geekidea.springbootplus.system.vo.SysDepartmentTreeVo;
+import org.mapstruct.Mapper;
+import org.mapstruct.factory.Mappers;
+
+import java.util.List;
+
+/**
+ * 部门对象转换器
+ *
+ * @author geekidea
+ * @date 2019-11-01
+ **/
+@Mapper
+public interface SysDepartmentConvert {
+
+    SysDepartmentConvert INSTANCE = Mappers.getMapper(SysDepartmentConvert.class);
+
+    /**
+     * SysDepartment转换成SysDepartmentTreeVo对象
+     *
+     * @param sysDepartment
+     * @return
+     */
+    SysDepartmentTreeVo entityToTreeVo(SysDepartment sysDepartment);
+
+    /**
+     * SysDepartment列表转换成SysDepartmentTreeVo列表
+     *
+     * @param list
+     * @return
+     */
+    List listToTreeVoList(List list);
+
+}
diff --git a/src/main/java/io/geekidea/springbootplus/system/service/SysDepartmentService.java b/src/main/java/io/geekidea/springbootplus/system/service/SysDepartmentService.java
index c3d8e63a..656a2b7c 100644
--- a/src/main/java/io/geekidea/springbootplus/system/service/SysDepartmentService.java
+++ b/src/main/java/io/geekidea/springbootplus/system/service/SysDepartmentService.java
@@ -16,13 +16,15 @@
 
 package io.geekidea.springbootplus.system.service;
 
-import io.geekidea.springbootplus.system.entity.SysDepartment;
 import io.geekidea.springbootplus.common.service.BaseService;
+import io.geekidea.springbootplus.common.vo.Paging;
+import io.geekidea.springbootplus.system.entity.SysDepartment;
 import io.geekidea.springbootplus.system.param.SysDepartmentQueryParam;
 import io.geekidea.springbootplus.system.vo.SysDepartmentQueryVo;
-import io.geekidea.springbootplus.common.vo.Paging;
+import io.geekidea.springbootplus.system.vo.SysDepartmentTreeVo;
 
 import java.io.Serializable;
+import java.util.List;
 
 /**
  * 
@@ -88,4 +90,16 @@ public interface SysDepartmentService extends BaseService {
      */
     boolean isEnableSysDepartment(Long id) throws Exception;
 
+    /**
+     * 获取所有可用的部门列表
+     * @return
+     */
+    List getAllDepartmentList();
+
+    /**
+     * 获取所有可用的部门树形列表
+     * @return
+     */
+    List getAllDepartmentTree();
+
 }
diff --git a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysDepartmentServiceImpl.java b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysDepartmentServiceImpl.java
index f794ce04..7f886ad2 100644
--- a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysDepartmentServiceImpl.java
+++ b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysDepartmentServiceImpl.java
@@ -23,17 +23,22 @@
 import io.geekidea.springbootplus.common.service.impl.BaseServiceImpl;
 import io.geekidea.springbootplus.common.vo.Paging;
 import io.geekidea.springbootplus.enums.StateEnum;
+import io.geekidea.springbootplus.system.convert.SysDepartmentConvert;
 import io.geekidea.springbootplus.system.entity.SysDepartment;
 import io.geekidea.springbootplus.system.mapper.SysDepartmentMapper;
 import io.geekidea.springbootplus.system.param.SysDepartmentQueryParam;
 import io.geekidea.springbootplus.system.service.SysDepartmentService;
 import io.geekidea.springbootplus.system.vo.SysDepartmentQueryVo;
+import io.geekidea.springbootplus.system.vo.SysDepartmentTreeVo;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
 
 
 /**
@@ -91,4 +96,47 @@ public boolean isEnableSysDepartment(Long id) throws Exception {
         return count > 0;
     }
 
+    @Override
+    public List getAllDepartmentList() {
+        SysDepartment sysDepartment = new SysDepartment().setState(StateEnum.ENABLE.ordinal());
+        // 获取所有已启用的部门列表
+        return sysDepartmentMapper.selectList(new QueryWrapper(sysDepartment));
+    }
+
+    @Override
+    public List getAllDepartmentTree() {
+        List sysDepartmentList = getAllDepartmentList();
+        if (CollectionUtils.isEmpty(sysDepartmentList)) {
+            throw new IllegalArgumentException("SysDepartment列表不能为空");
+        }
+        List list = SysDepartmentConvert.INSTANCE.listToTreeVoList(sysDepartmentList);
+        List treeVos = new ArrayList<>();
+        for (SysDepartmentTreeVo treeVo : list) {
+            if (treeVo.getParentId() == null) {
+                treeVos.add(findChildren(treeVo, list));
+            }
+        }
+        return treeVos;
+    }
+
+    /**
+     * 递归获取树形结果列表
+     *
+     * @param tree
+     * @param list
+     * @return
+     */
+    public SysDepartmentTreeVo findChildren(SysDepartmentTreeVo tree, List list) {
+        for (SysDepartmentTreeVo vo : list) {
+            if (tree.getId().equals(vo.getParentId())) {
+                if (tree.getChildren() == null) {
+                    tree.setChildren(new ArrayList<>());
+                }
+                tree.getChildren().add(findChildren(vo, list));
+            }
+        }
+        return tree;
+    }
+
+
 }
diff --git a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysPermissionServiceImpl.java b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysPermissionServiceImpl.java
index 409d6466..a9467d99 100644
--- a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysPermissionServiceImpl.java
+++ b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysPermissionServiceImpl.java
@@ -142,6 +142,9 @@ public List getAllMenuTree() throws Exception {
 
     @Override
     public List convertSysPermissionTreeVoList(List list) {
+        if (CollectionUtils.isEmpty(list)) {
+            throw new IllegalArgumentException("SysPermission列表不能为空");
+        }
         // 按level分组获取map
         Map> map = list.stream().collect(Collectors.groupingBy(SysPermission::getLevel));
         List treeVos = new ArrayList<>();
diff --git a/src/main/java/io/geekidea/springbootplus/system/vo/SysDepartmentTreeVo.java b/src/main/java/io/geekidea/springbootplus/system/vo/SysDepartmentTreeVo.java
new file mode 100644
index 00000000..b6d9b4c0
--- /dev/null
+++ b/src/main/java/io/geekidea/springbootplus/system/vo/SysDepartmentTreeVo.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2019-2029 geekidea(https://github.com/geekidea)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.geekidea.springbootplus.system.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 
+ * 部门TreeVo
+ * 
+ * + * @author geekidea + * @since 2019-11-1 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "SysDepartmentTreeVo对象", description = "部门") +public class SysDepartmentTreeVo implements Serializable { + private static final long serialVersionUID = -2250233632748939400L; + + @ApiModelProperty(value = "主键") + private Long id; + + @ApiModelProperty(value = "部门名称") + private String name; + + @ApiModelProperty(value = "父id") + private Long parentId; + + @ApiModelProperty(value = "状态,0:禁用,1:启用") + private Integer state; + + @ApiModelProperty(value = "排序") + private Integer sort; + + @ApiModelProperty(value = "备注") + private String remark; + + @ApiModelProperty(value = "版本") + private Integer version; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @ApiModelProperty(value = "修改时间") + private Date updateTime; + + private List children; + +} diff --git a/src/main/java/io/geekidea/springbootplus/util/Jackson.java b/src/main/java/io/geekidea/springbootplus/util/Jackson.java new file mode 100644 index 00000000..9ddc63fe --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/util/Jackson.java @@ -0,0 +1,62 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.util; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +/** + * Jackson序列化工具类 + * + * @author geekidea + * @date 2019-11-01 + **/ +public class Jackson { + + /** + * 键按自然顺序输出 + * + * @param object + * @return + */ + public static String toJsonString(Object object) { + return toJsonString(object, false); + } + + /** + * 键按自然顺序格式化输出 + * + * @param object + * @param prettyFormat + * @return + */ + public static String toJsonString(Object object, boolean prettyFormat) { + ObjectMapper objectMapper = new ObjectMapper(); + try { + //格式化输出 + objectMapper.configure(SerializationFeature.INDENT_OUTPUT, prettyFormat); + //键按自然顺序输出 + objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); + return objectMapper.writeValueAsString(object); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 34b4a877..ffb8d222 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -145,10 +145,10 @@ spring-boot-plus: /templates/**=anon /druid/**=anon /hello/world=anon - /ip/**=anon /sysLog/**=anon /verificationCode/**=anon /resource/**=anon + /fooBar/**=anon # 权限配置 permission: # 排除登陆登出相关 diff --git a/src/main/resources/mapper/foobar/FooBarMapper.xml b/src/main/resources/mapper/foobar/FooBarMapper.xml new file mode 100644 index 00000000..e2aae616 --- /dev/null +++ b/src/main/resources/mapper/foobar/FooBarMapper.xml @@ -0,0 +1,22 @@ + + + + + + + id, name, foo, bar, remark, state, version, create_time, update_time + + + + + + + diff --git a/src/main/resources/mapper/package.json b/src/main/resources/mapper/package.json deleted file mode 100644 index 234b94ae..00000000 --- a/src/main/resources/mapper/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "mapper", - "description": "Mybatis Mapper XML" -} diff --git a/src/main/resources/static/favicon.ico b/src/main/resources/static/favicon.ico new file mode 100644 index 00000000..bd5a6781 Binary files /dev/null and b/src/main/resources/static/favicon.ico differ diff --git a/src/main/resources/static/verifyCode.html b/src/main/resources/static/verifyCode.html index 792e58f6..916e504d 100644 --- a/src/main/resources/static/verifyCode.html +++ b/src/main/resources/static/verifyCode.html @@ -21,6 +21,49 @@ 验证码 - + +
+

方式一:获取图片

+ +

verifyToken:查看Responses Headers

+
+ +
+ +
+

方式二:获取base64图片编码

+ +

+
+ + + \ No newline at end of file diff --git a/src/test/java/io/geekidea/springbootplus/test/SpringBootPlusGenerator.java b/src/test/java/io/geekidea/springbootplus/test/SpringBootPlusGenerator.java index f28db02c..70049e23 100644 --- a/src/test/java/io/geekidea/springbootplus/test/SpringBootPlusGenerator.java +++ b/src/test/java/io/geekidea/springbootplus/test/SpringBootPlusGenerator.java @@ -41,7 +41,7 @@ public static void main(String[] args) { // 组件作者等配置 codeGenerator - .setModuleName("system") + .setModuleName("foobar") .setAuthor("geekidea") .setPkIdColumnName("id"); @@ -67,7 +67,7 @@ public static void main(String[] args) { .setGeneratorMapperXml(true); // 是否生成Shiro RequiresPermissions注解 - codeGenerator.setRequiresPermissions(true); + codeGenerator.setRequiresPermissions(false); // 是否覆盖已有文件 codeGenerator.setFileOverride(true); @@ -78,9 +78,7 @@ public static void main(String[] args) { // 需要生成的表数组 // xxx,yyy,zzz为需要生成代码的表名称 String[] tables = { - "xxx", - "yyy", - "zzz" + "foo_bar" }; // 循环生成