From c727a49455f665d27695056fb5049f55766e0d40 Mon Sep 17 00:00:00 2001 From: sunchenbin Date: Sat, 18 May 2019 19:14:00 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=B9timestamp/time/d?= =?UTF-8?q?ate/float=E6=95=B0=E6=8D=AE=E5=BA=93=E5=AD=97=E6=AE=B5=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mybatis-enhance-actable/LICENSE | 201 ++++++++++++++++++ .../actable/constants/MySqlTypeConstant.java | 18 +- .../manager/common/BaseMysqlCRUDManager.java | 9 + .../common/BaseMysqlCRUDManagerImpl.java | 5 + .../SysOracleCreateTableManagerImpl.java | 4 +- .../system/CreateMysqlTablesMapper.xml | 2 +- 6 files changed, 233 insertions(+), 6 deletions(-) create mode 100644 mybatis-enhance-actable/LICENSE diff --git a/mybatis-enhance-actable/LICENSE b/mybatis-enhance-actable/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/mybatis-enhance-actable/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/constants/MySqlTypeConstant.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/constants/MySqlTypeConstant.java index cea38ab..00f58be 100644 --- a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/constants/MySqlTypeConstant.java +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/constants/MySqlTypeConstant.java @@ -42,9 +42,21 @@ public class MySqlTypeConstant { @LengthCount public static final String CHAR = "char"; - /** - * 等于java中的long - */ @LengthCount public static final String BIGINT = "bigint"; + + @LengthCount(LengthCount=0) + public static final String BIT = "bit"; + + @LengthCount(LengthCount=0) + public static final String TIMESTAMP = "timestamp"; + + @LengthCount(LengthCount=0) + public static final String DATE = "date"; + + @LengthCount(LengthCount=0) + public static final String TIME = "time"; + + @LengthCount(LengthCount=0) + public static final String FLOAT = "float"; } diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManager.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManager.java index 549d3db..9c35241 100644 --- a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManager.java +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManager.java @@ -35,6 +35,15 @@ public interface BaseMysqlCRUDManager{ */ PageResultCommand search(T t); + /** + * 废弃,请使用search + * 根据传入对象非空的条件进行查询返回值PageResultCommand,适用于返回结果集的场合 + * @param model类型 + * @param t 要查询的model类型数据 + */ + @Deprecated + PageResultCommand query(T t); + /** * 根据传入对象非空的条件进行查询返回对象,适用于返回单个对象的场合 * @param t diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManagerImpl.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManagerImpl.java index 3869a69..713c2c1 100644 --- a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManagerImpl.java +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManagerImpl.java @@ -228,6 +228,11 @@ public class BaseMysqlCRUDManagerImpl implements BaseMysqlCRUDManager{ return pageResultCommand; } + @Override + public PageResultCommand query(T t) { + return search(t); + } + /** * 递归扫描父类的fields * @param clas diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysOracleCreateTableManagerImpl.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysOracleCreateTableManagerImpl.java index 445a8d1..0688da1 100644 --- a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysOracleCreateTableManagerImpl.java +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysOracleCreateTableManagerImpl.java @@ -28,13 +28,13 @@ public class SysOracleCreateTableManagerImpl implements SysOracleCreateTableMana /** * 要扫描的model所在的pack */ - @Value("#{configProperties['mybatis.model.pack']}") +// @Value("#{configProperties['mybatis.model.pack']}") private String pack; /** * 自动创建模式:update表示更新,create表示删除原表重新创建 */ - @Value("#{configProperties['mybatis.table.auto']}") +// @Value("#{configProperties['mybatis.table.auto']}") private String tableAuto; /** diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/mapping/system/CreateMysqlTablesMapper.xml b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/mapping/system/CreateMysqlTablesMapper.xml index 2b66e3a..0781e8d 100644 --- a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/mapping/system/CreateMysqlTablesMapper.xml +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/mapping/system/CreateMysqlTablesMapper.xml @@ -2,7 +2,7 @@ - + -- Gitee From 25598dcde3b49a24a91019d39b6b1cb84d60f2d9 Mon Sep 17 00:00:00 2001 From: sunchenbin Date: Sun, 19 May 2019 00:00:14 +0800 Subject: [PATCH 2/7] =?UTF-8?q?version=201.0.5=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=AF=B9springboot=E7=9A=84=E6=94=AF=E6=8C=81=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=94=AF=E6=8C=81=E7=9A=84mysql=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AD=97=E6=AE=B5=EF=BC=88timestamp/date/tim?= =?UTF-8?q?e/float=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mybatis-enhance-actable/pom.xml | 2 +- .../mybatis/actable/constants/Constants.java | 15 +++ .../common/BaseMysqlCRUDManagerImpl.java | 12 +- .../manager/handler/StartUpHandlerImpl.java | 14 ++- .../SysMysqlCreateTableManagerImpl.java | 28 +++-- .../SysOracleCreateTableManagerImpl.java | 10 +- .../manager/util/ConfigurationUtil.java | 116 ++++++++++++++++++ 7 files changed, 180 insertions(+), 17 deletions(-) create mode 100644 mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/constants/Constants.java create mode 100644 mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/util/ConfigurationUtil.java diff --git a/mybatis-enhance-actable/pom.xml b/mybatis-enhance-actable/pom.xml index 6c579bf..74dba06 100644 --- a/mybatis-enhance-actable/pom.xml +++ b/mybatis-enhance-actable/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.gitee.sunchenbin.mybatis.actable mybatis-enhance-actable - 1.0.4 + 1.0.5 org.sonatype.oss diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/constants/Constants.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/constants/Constants.java new file mode 100644 index 0000000..69e42ee --- /dev/null +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/constants/Constants.java @@ -0,0 +1,15 @@ +package com.gitee.sunchenbin.mybatis.actable.constants; + +public class Constants { + + public static final String DATABASE_TYPE_KEY = "mybatis.database.type"; + public static final String MODEL_PACK_KEY = "mybatis.model.pack"; + public static final String TABLE_AUTO_KEY = "mybatis.table.auto"; + + public static final String DATABASE_TYPE_KEY_VALUE = "${mybatis.database.type:NULL}"; + public static final String MODEL_PACK_KEY_VALUE = "${mybatis.model.pack:NULL}"; + public static final String TABLE_AUTO_KEY_VALUE = "${mybatis.table.auto:NULL}"; + + public static final String NULL = "NULL"; + +} diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManagerImpl.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManagerImpl.java index 713c2c1..de2078f 100644 --- a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManagerImpl.java +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/common/BaseMysqlCRUDManagerImpl.java @@ -2,12 +2,12 @@ package com.gitee.sunchenbin.mybatis.actable.manager.common; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.apache.commons.lang.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -242,7 +242,15 @@ public class BaseMysqlCRUDManagerImpl implements BaseMysqlCRUDManager{ private Field[] recursionParents(Class clas, Field[] fields) { if(clas.getSuperclass()!=null){ Class clsSup = clas.getSuperclass(); - fields = (Field[]) ArrayUtils.addAll(fields,clsSup.getDeclaredFields()); + List fieldList = new ArrayList(); + fieldList.addAll(Arrays.asList(fields)); + fieldList.addAll(Arrays.asList(clsSup.getDeclaredFields())); + fields = new Field[fieldList.size()]; + int i = 0; + for (Object field : fieldList.toArray()) { + fields[i] = (Field) field; + i++; + } fields = recursionParents(clsSup, fields); } return fields; diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/handler/StartUpHandlerImpl.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/handler/StartUpHandlerImpl.java index 8a8dbab..7056b57 100644 --- a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/handler/StartUpHandlerImpl.java +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/handler/StartUpHandlerImpl.java @@ -8,7 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import com.gitee.sunchenbin.mybatis.actable.constants.Constants; import com.gitee.sunchenbin.mybatis.actable.manager.system.SysMysqlCreateTableManager; +import com.gitee.sunchenbin.mybatis.actable.manager.util.ConfigurationUtil; /** * 启动时进行处理的实现类 @@ -21,6 +23,9 @@ public class StartUpHandlerImpl implements StartUpHandler { private static final Logger log = LoggerFactory.getLogger(StartUpHandlerImpl.class); + @Autowired + private ConfigurationUtil springContextUtil; + /** 数据库类型:mysql */ public static String MYSQL = "mysql"; @@ -33,17 +38,16 @@ public class StartUpHandlerImpl implements StartUpHandler { /** 数据库类型:postgresql */ public static String POSTGRESQL = "postgresql"; - /** - * 数据库类型 - */ - @Value("#{configProperties['mybatis.database.type']}") - private String databaseType = MYSQL; + /** 数据库类型 */ + private static String databaseType = null; @Autowired private SysMysqlCreateTableManager sysMysqlCreateTableManager; @PostConstruct public void startHandler() { + // 获取配置信息 + databaseType = springContextUtil.getConfig(Constants.DATABASE_TYPE_KEY) == null ? MYSQL : springContextUtil.getConfig(Constants.DATABASE_TYPE_KEY); // 执行mysql的处理方法 if (MYSQL.equals(databaseType)) { diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysMysqlCreateTableManagerImpl.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysMysqlCreateTableManagerImpl.java index bee7582..d7a1b8b 100644 --- a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysMysqlCreateTableManagerImpl.java +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysMysqlCreateTableManagerImpl.java @@ -2,13 +2,13 @@ package com.gitee.sunchenbin.mybatis.actable.manager.system; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import org.apache.commons.lang.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -21,8 +21,10 @@ import com.gitee.sunchenbin.mybatis.actable.annotation.LengthCount; import com.gitee.sunchenbin.mybatis.actable.annotation.Table; import com.gitee.sunchenbin.mybatis.actable.command.CreateTableParam; import com.gitee.sunchenbin.mybatis.actable.command.SysMysqlColumns; +import com.gitee.sunchenbin.mybatis.actable.constants.Constants; import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant; import com.gitee.sunchenbin.mybatis.actable.dao.system.CreateMysqlTablesMapper; +import com.gitee.sunchenbin.mybatis.actable.manager.util.ConfigurationUtil; import com.gitee.sunchenbin.mybatis.actable.utils.ClassTools; /** @@ -39,23 +41,27 @@ public class SysMysqlCreateTableManagerImpl implements SysMysqlCreateTableManage @Autowired private CreateMysqlTablesMapper createMysqlTablesMapper; + + @Autowired + private ConfigurationUtil springContextUtil; /** * 要扫描的model所在的pack */ - @Value("#{configProperties['mybatis.model.pack']}") - private String pack; + private static String pack = null; /** * 自动创建模式:update表示更新,create表示删除原表重新创建 */ - @Value("#{configProperties['mybatis.table.auto']}") - private String tableAuto; - + private static String tableAuto = null; + /** * 读取配置文件的三种状态(创建表、更新表、不做任何事情) */ public void createMysqlTable() { + // 读取配置信息 + pack = springContextUtil.getConfig(Constants.MODEL_PACK_KEY); + tableAuto = springContextUtil.getConfig(Constants.TABLE_AUTO_KEY); // 不做任何事情 if ("none".equals(tableAuto)) { @@ -482,7 +488,15 @@ public class SysMysqlCreateTableManagerImpl implements SysMysqlCreateTableManage private Field[] recursionParents(Class clas, Field[] fields) { if (clas.getSuperclass() != null) { Class clsSup = clas.getSuperclass(); - fields = (Field[]) ArrayUtils.addAll(fields, clsSup.getDeclaredFields()); + List fieldList = new ArrayList(); + fieldList.addAll(Arrays.asList(fields)); + fieldList.addAll(Arrays.asList(clsSup.getDeclaredFields())); + fields = new Field[fieldList.size()]; + int i = 0; + for (Object field : fieldList.toArray()) { + fields[i] = (Field) field; + i++; + } fields = recursionParents(clsSup, fields); } return fields; diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysOracleCreateTableManagerImpl.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysOracleCreateTableManagerImpl.java index 0688da1..8f8596e 100644 --- a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysOracleCreateTableManagerImpl.java +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/system/SysOracleCreateTableManagerImpl.java @@ -7,7 +7,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.gitee.sunchenbin.mybatis.actable.constants.Constants; import com.gitee.sunchenbin.mybatis.actable.dao.system.CreateMysqlTablesMapper; +import com.gitee.sunchenbin.mybatis.actable.manager.util.ConfigurationUtil; /** * 项目启动时自动扫描配置的目录中的model,根据配置的规则自动创建或更新表 @@ -24,23 +26,27 @@ public class SysOracleCreateTableManagerImpl implements SysOracleCreateTableMana @Autowired private CreateMysqlTablesMapper createMysqlTablesMapper; + + @Autowired + private ConfigurationUtil springContextUtil; /** * 要扫描的model所在的pack */ -// @Value("#{configProperties['mybatis.model.pack']}") private String pack; /** * 自动创建模式:update表示更新,create表示删除原表重新创建 */ -// @Value("#{configProperties['mybatis.table.auto']}") private String tableAuto; /** * 读取配置文件的三种状态(创建表、更新表、不做任何事情) */ public void createOracleTable(){ + // 读取配置信息 + pack = springContextUtil.getConfig(Constants.MODEL_PACK_KEY); + tableAuto = springContextUtil.getConfig(Constants.TABLE_AUTO_KEY); // 不做任何事情 if("none".equals(tableAuto)){ diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/util/ConfigurationUtil.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/util/ConfigurationUtil.java new file mode 100644 index 0000000..f8b65ce --- /dev/null +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/manager/util/ConfigurationUtil.java @@ -0,0 +1,116 @@ +package com.gitee.sunchenbin.mybatis.actable.manager.util; + +import java.lang.reflect.Method; +import java.util.Properties; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.config.PropertyResourceConfigurer; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.core.io.support.PropertiesLoaderSupport; +import org.springframework.stereotype.Component; + +import com.gitee.sunchenbin.mybatis.actable.constants.Constants; + +@Component +public class ConfigurationUtil implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + private static Properties properties = null; + + @Value(Constants.TABLE_AUTO_KEY_VALUE) + private String tableAuto; + + @Value(Constants.MODEL_PACK_KEY_VALUE) + private String modelPack; + + @Value(Constants.DATABASE_TYPE_KEY_VALUE) + private String databaseType; + + /** + * 实现ApplicationContextAware接口的回调方法,设置上下文环境 + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) { + ConfigurationUtil.applicationContext = applicationContext; + } + + /** + * 获得spring上下文 + * + * @return ApplicationContext spring上下文 + */ + public ApplicationContext getApplicationContext() { + return applicationContext; + } + + /** + * 获取bean + * + * @param name + * service注解方式name为小驼峰格式 + * @return Object bean的实例对象 + */ + public Object getBean(String name) throws BeansException { + return applicationContext.getBean(name); + } + + /** + * 获取配置文件的值,兼容传统spring项目和springboot项目 + * + * @param key + * properties + * @return + */ + public String getConfig(String key) { + if(Constants.DATABASE_TYPE_KEY.equals(key) && !Constants.NULL.equals(databaseType)) { + return databaseType; + } + if(Constants.MODEL_PACK_KEY.equals(key) && !Constants.NULL.equals(modelPack)) { + return modelPack; + } + if(Constants.TABLE_AUTO_KEY.equals(key) && !Constants.NULL.equals(tableAuto)) { + return tableAuto; + } + if(properties == null) { + initProperties(); + } + Object object = properties.get(key); + return object == null ? null : (String)object; + } + + private void initProperties() { + + properties = new Properties(); + try { + String[] postProcessorNames = applicationContext.getBeanNamesForType(BeanFactoryPostProcessor.class, true, + true); + for (String ppName : postProcessorNames) { + BeanFactoryPostProcessor beanProcessor = applicationContext.getBean(ppName, + BeanFactoryPostProcessor.class); + if (beanProcessor instanceof PropertyResourceConfigurer) { + PropertyResourceConfigurer propertyResourceConfigurer = (PropertyResourceConfigurer) beanProcessor; + Method mergeProperties = PropertiesLoaderSupport.class.getDeclaredMethod("mergeProperties"); + mergeProperties.setAccessible(true); + Properties props = (Properties) mergeProperties.invoke(propertyResourceConfigurer); + + // get the method convertProperties + // in class PropertyResourceConfigurer + Method convertProperties = PropertyResourceConfigurer.class.getDeclaredMethod("convertProperties", + Properties.class); + // convert properties + convertProperties.setAccessible(true); + convertProperties.invoke(propertyResourceConfigurer, props); + + properties.putAll(props); + } + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} -- Gitee From 21b8fa323f202d6207fffb75ca151630c3d674b9 Mon Sep 17 00:00:00 2001 From: sun5769675 Date: Sun, 19 May 2019 00:27:23 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README.md=201.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9mysql=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=EF=BC=88timestamp/time/date/float=EF=BC=89=E5=9B=9B=E7=A7=8D?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=94=AF=E6=8C=81?= =?UTF-8?q?(=E7=89=88=E6=9C=AC1.0.5)=202.=20=E5=A2=9E=E5=8A=A0=E5=AF=B9spr?= =?UTF-8?q?ingboot=E6=A1=86=E6=9E=B6=E7=9A=84=E6=94=AF=E6=8C=81(=E7=89=88?= =?UTF-8?q?=E6=9C=AC1.0.5)=203.=20=E7=BB=B4=E6=8A=A4springboot=E7=9A=84?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 20ad94c..c563bdc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# mybatis-enhance-actable-1.0.4 +# mybatis-enhance-actable-1.0.5 该项目是从之前写过的一个框架中抽取出来的,本身是对Mybatis做的增强功能,为了能够使习惯了hibernate框架的开发者能够快速的入手Mybatis,我给他取名叫做 “A.C.Table” 本意是自动建表的意思,A.C.Table是一个基于Spring和Mybatis的Maven项目,增强了Mybatis的功能,过配置model注解的方式来创建表,修改表结构,并且实现了共通的CUDR功能提升开发效率,目前仅支持Mysql,后续可能会扩展针对其他数据库的支持。 @@ -14,19 +14,21 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 7. 修复了model属性名与表字段名不一致时公共的查询方法查不出数据的问题。(版本1.0.2) 8. 增加了对公共的CUDR方法的优化,保存成功会返回id,query查询时可以设置参数进行分页查询(pageSize:int类型标识每页数量,currentPage:int类型标识当前第几页,start:int类型从第几条开始,orderField:string类型排序字段,sortStr:string类型排序方式(desc,asc))(版本1.0.3) 9. 增加了对Mysql的longtext和mediumtext两种字段类型的支持,公共的CUDR方法的优化,原query方法更正为search,现query方法支持动态sql查询,原orderField字段只支持单个字段的排序,现修改为orderBy字段,支持数据类型为LinkedHashMap,有序,key为字段名,value为排序方式(版本1.0.4) +10.增加对mysql数据库(timestamp/time/date/float)四种数据类型的支持(版本1.0.5) +11.增加对springboot框架的支持(版本1.0.5) - **使用步骤方法** -1. 使用该功能的项目需要依赖mybatis-enhance-actable-1.0.3.jar + **基本使用规范** +1. 需要依赖mybatis-enhance-actable-1.0.5.jar - 已上传至maven中央仓库,使用时pom文件中增加如下依赖 com.gitee.sunchenbin.mybatis.actable mybatis-enhance-actable - 1.0.4 + 1.0.5 -2. 在你的web项目上创建个目录比如config下面创建个文件autoCreateTable.properties文件的内容如下: - mybatis.table.auto=update +2. 需要配置对于actable支持的配置 + + mybatis.table.auto=update mybatis.model.pack=com.sunchenbin.store.model @@ -43,6 +45,55 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 2.4 mybatis.model.pack这个配置是用来配置要扫描的用于创建表的对象的包名 2.5 mybatis.database.type这个是用来区别数据库的,预计会支持这四种数据库mysql/oracle/sqlserver/postgresql,但目前仅支持mysql + +3. 支持actable的mybatis配置 + + + 1. classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml + 2. com.gitee.sunchenbin.mybatis.actable.dao.* + +4. 扫描actable的包到spring容器中管理 + + 1. com.gitee.sunchenbin.mybatis.actable.manager.* + + **Springboot+Mybatis的项目使用步骤方法** + +1. 首先pom文件依赖actable框架 + + + com.gitee.sunchenbin.mybatis.actable + mybatis-enhance-actable + 1.0.5 + + +2. 项目的application.properties文件配置例如下面 + + mybatis.table.auto=update + mybatis.model.pack=com.sunchenbin.store.model + mybatis.database.type=mysql + mybatis.mapperLocations=classpath*:xxxxxx/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml + +3. springboot启动类需要做如下配置 + + 1. 通过注解@ComponentScan配置,扫描actable要注册到spring的包路径"com.gitee.sunchenbin.mybatis.actable.manager.*" + 2. 通过注解@MapperScan配置,扫描mybatis的mapper,路径为"com.gitee.sunchenbin.mybatis.actable.dao.*" + + **传统Spring+Mybatis的Web项目使用步骤方法** +1. 首先pom文件依赖actable框架 + + + com.gitee.sunchenbin.mybatis.actable + mybatis-enhance-actable + 1.0.5 + + +2. 在你的web项目上创建个目录比如config下面创建个文件autoCreateTable.properties文件的内容如下: + + mybatis.table.auto=update + + mybatis.model.pack=com.sunchenbin.store.model + + mybatis.database.type=mysql 3. spring的配置文件中需要做如下配置: ``` -- Gitee From d05f9919688ae1405266803f9e059b11b94e1fc4 Mon Sep 17 00:00:00 2001 From: sun5769675 Date: Sun, 19 May 2019 00:29:36 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README.md=201.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9mysql=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=EF=BC=88timestamp/time/date/float=EF=BC=89=E5=9B=9B=E7=A7=8D?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=94=AF=E6=8C=81?= =?UTF-8?q?(=E7=89=88=E6=9C=AC1.0.5)=202.=20=E5=A2=9E=E5=8A=A0=E5=AF=B9spr?= =?UTF-8?q?ingboot=E6=A1=86=E6=9E=B6=E7=9A=84=E6=94=AF=E6=8C=81(=E7=89=88?= =?UTF-8?q?=E6=9C=AC1.0.5)=203.=20=E7=BB=B4=E6=8A=A4springboot=E7=9A=84?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index c563bdc..7f4ff6c 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,7 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 2. 需要配置对于actable支持的配置 mybatis.table.auto=update - mybatis.model.pack=com.sunchenbin.store.model - mybatis.database.type=mysql 本系统提供三种模式: @@ -90,9 +88,7 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 2. 在你的web项目上创建个目录比如config下面创建个文件autoCreateTable.properties文件的内容如下: mybatis.table.auto=update - mybatis.model.pack=com.sunchenbin.store.model - mybatis.database.type=mysql 3. spring的配置文件中需要做如下配置: -- Gitee From 646d67119fdf928d5e992e8e08808ecb297a10d0 Mon Sep 17 00:00:00 2001 From: sun5769675 Date: Sun, 19 May 2019 00:31:48 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README.md=201.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9mysql=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=EF=BC=88timestamp/time/date/float=EF=BC=89=E5=9B=9B=E7=A7=8D?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=94=AF=E6=8C=81?= =?UTF-8?q?(=E7=89=88=E6=9C=AC1.0.5)=202.=20=E5=A2=9E=E5=8A=A0=E5=AF=B9spr?= =?UTF-8?q?ingboot=E6=A1=86=E6=9E=B6=E7=9A=84=E6=94=AF=E6=8C=81(=E7=89=88?= =?UTF-8?q?=E6=9C=AC1.0.5)=203.=20=E7=BB=B4=E6=8A=A4springboot=E7=9A=84?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 7f4ff6c..4bad9d8 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 2. 需要配置对于actable支持的配置 +``` mybatis.table.auto=update mybatis.model.pack=com.sunchenbin.store.model mybatis.database.type=mysql @@ -44,11 +45,17 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 2.5 mybatis.database.type这个是用来区别数据库的,预计会支持这四种数据库mysql/oracle/sqlserver/postgresql,但目前仅支持mysql +``` + 3. 支持actable的mybatis配置 +``` 1. classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml 2. com.gitee.sunchenbin.mybatis.actable.dao.* +``` + + 4. 扫描actable的包到spring容器中管理 @@ -66,10 +73,12 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 2. 项目的application.properties文件配置例如下面 +``` mybatis.table.auto=update mybatis.model.pack=com.sunchenbin.store.model mybatis.database.type=mysql mybatis.mapperLocations=classpath*:xxxxxx/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml +``` 3. springboot启动类需要做如下配置 -- Gitee From 17c38b650d5937b6fa296f30d4207952ba8da0cc Mon Sep 17 00:00:00 2001 From: sun5769675 Date: Sun, 19 May 2019 00:33:39 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README.md=201.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9mysql=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=EF=BC=88timestamp/time/date/float=EF=BC=89=E5=9B=9B=E7=A7=8D?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=94=AF=E6=8C=81?= =?UTF-8?q?(=E7=89=88=E6=9C=AC1.0.5)=202.=20=E5=A2=9E=E5=8A=A0=E5=AF=B9spr?= =?UTF-8?q?ingboot=E6=A1=86=E6=9E=B6=E7=9A=84=E6=94=AF=E6=8C=81(=E7=89=88?= =?UTF-8?q?=E6=9C=AC1.0.5)=203.=20=E7=BB=B4=E6=8A=A4springboot=E7=9A=84?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4bad9d8..2cf208e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 2. 需要配置对于actable支持的配置 ``` - mybatis.table.auto=update + mybatis.table.auto=update mybatis.model.pack=com.sunchenbin.store.model mybatis.database.type=mysql @@ -50,7 +50,7 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 3. 支持actable的mybatis配置 ``` - + 1. classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml 2. com.gitee.sunchenbin.mybatis.actable.dao.* ``` @@ -74,10 +74,10 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 2. 项目的application.properties文件配置例如下面 ``` - mybatis.table.auto=update + mybatis.table.auto=update mybatis.model.pack=com.sunchenbin.store.model mybatis.database.type=mysql - mybatis.mapperLocations=classpath*:xxxxxx/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml + mybatis.mapperLocations=classpath*:xxxxxx/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml ``` 3. springboot启动类需要做如下配置 -- Gitee From aab6056321e3134ba36d5c3bd56fa5d27491f208 Mon Sep 17 00:00:00 2001 From: sun5769675 Date: Sun, 19 May 2019 00:36:40 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2cf208e..5629eed 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,13 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 **基本使用规范** 1. 需要依赖mybatis-enhance-actable-1.0.5.jar +``` com.gitee.sunchenbin.mybatis.actable mybatis-enhance-actable 1.0.5 +``` 2. 需要配置对于actable支持的配置 @@ -59,18 +61,22 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 4. 扫描actable的包到spring容器中管理 +``` 1. com.gitee.sunchenbin.mybatis.actable.manager.* +``` **Springboot+Mybatis的项目使用步骤方法** 1. 首先pom文件依赖actable框架 +``` com.gitee.sunchenbin.mybatis.actable mybatis-enhance-actable 1.0.5 - +``` + 2. 项目的application.properties文件配置例如下面 ``` @@ -82,27 +88,33 @@ A.C.Table是采用了Spring、Mybatis技术的Maven结构,详细介绍如下 3. springboot启动类需要做如下配置 +``` 1. 通过注解@ComponentScan配置,扫描actable要注册到spring的包路径"com.gitee.sunchenbin.mybatis.actable.manager.*" 2. 通过注解@MapperScan配置,扫描mybatis的mapper,路径为"com.gitee.sunchenbin.mybatis.actable.dao.*" +``` **传统Spring+Mybatis的Web项目使用步骤方法** 1. 首先pom文件依赖actable框架 +``` com.gitee.sunchenbin.mybatis.actable mybatis-enhance-actable 1.0.5 +``` 2. 在你的web项目上创建个目录比如config下面创建个文件autoCreateTable.properties文件的内容如下: +``` mybatis.table.auto=update mybatis.model.pack=com.sunchenbin.store.model mybatis.database.type=mysql - +``` + 3. spring的配置文件中需要做如下配置: ``` - + -- Gitee