diff --git a/mybatis-enhance-actable/.classpath b/mybatis-enhance-actable/.classpath index 4753f69fbc0a7a41a162085954eaa9967ccd5077..6d4d1ba20f81dc3a424bb5a2b8ec4f8385259230 100644 --- a/mybatis-enhance-actable/.classpath +++ b/mybatis-enhance-actable/.classpath @@ -6,7 +6,7 @@ - + @@ -14,7 +14,6 @@ - diff --git a/mybatis-enhance-actable/.settings/org.eclipse.jdt.core.prefs b/mybatis-enhance-actable/.settings/org.eclipse.jdt.core.prefs index 45a6e0e0d5a1eaa3749e63e9d8aabfb3169f19ee..69c31cd493ce042398e9fe93d22b72beb46afa88 100644 --- a/mybatis-enhance-actable/.settings/org.eclipse.jdt.core.prefs +++ b/mybatis-enhance-actable/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,8 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/mybatis-enhance-actable/pom.xml b/mybatis-enhance-actable/pom.xml index 906e96556fe34a205395c7a1f0ba349e271d0794..eb4f67af9977e6f5f713796baa81bc31896a95de 100644 --- a/mybatis-enhance-actable/pom.xml +++ b/mybatis-enhance-actable/pom.xml @@ -40,7 +40,7 @@ - 4.1.4.RELEASE + 4.3.7.RELEASE @@ -67,12 +67,26 @@ provided - + + + + org.mybatis + mybatis + 3.4.3 + provided + + + + org.apache.commons + commons-lang3 + 3.4 + provided + diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/command/SaveOrUpdateDataCommand.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/command/SaveOrUpdateDataCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..01394ecc31debf9f0aa672febdbf86da478bada9 --- /dev/null +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/command/SaveOrUpdateDataCommand.java @@ -0,0 +1,37 @@ +package com.gitee.sunchenbin.mybatis.actable.command; + +import java.util.Map; + +public class SaveOrUpdateDataCommand { + + private Integer id; + + private Map> tableMap; + + public SaveOrUpdateDataCommand(){ + + } + + public SaveOrUpdateDataCommand(Map> tableMap){ + this.tableMap = tableMap; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Map> getTableMap() { + return tableMap; + } + + public void setTableMap(Map> tableMap) { + this.tableMap = tableMap; + } + +} + + diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/dao/common/BaseMysqlCRUDMapper.java b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/dao/common/BaseMysqlCRUDMapper.java index 948a5a51e66b0432ad5ad1bf22df8d7edaafb4d3..883e845835368085ade982878c2d06d2230ef2a1 100644 --- a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/dao/common/BaseMysqlCRUDMapper.java +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/dao/common/BaseMysqlCRUDMapper.java @@ -4,6 +4,9 @@ import java.util.List; import java.util.Map; import org.apache.ibatis.annotations.Param; +import org.springframework.transaction.annotation.Transactional; + +import com.gitee.sunchenbin.mybatis.actable.command.SaveOrUpdateDataCommand; /** @@ -11,19 +14,20 @@ import org.apache.ibatis.annotations.Param; * @author sunchenbin * */ +@Transactional public interface BaseMysqlCRUDMapper { /** * 保存 * @param tableMap 表结构的map */ - public void save(@Param("tableMap") Map> tableMap); + public void save(SaveOrUpdateDataCommand saveOrUpdateDataCommand); /** * 更新 * @param tableMap 表结构的map */ - public void update(@Param("tableMap") Map> tableMap); + public void update(SaveOrUpdateDataCommand saveOrUpdateDataCommand); /** * 删除 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 b8026fd2e6d43d90d5a8e79b13118b66fa605c6f..3d3a95876dd65be9a89484552db8afc21c3e2fdd 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 @@ -8,8 +8,9 @@ public interface BaseMysqlCRUDManager{ * 保存,如果主键有值则进行更新操作 * @param model类型 * @param t 要保存的model类型数据 + * @return id 操作数据的id */ - void save(T t); + Integer save(T 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 502c68404bc973d27227cdc1880a79f4d3b1bdc9..0d966e62c1852953969f6e3a58569a15212d12b8 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 @@ -6,7 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang3.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional; import com.gitee.sunchenbin.mybatis.actable.annotation.Column; import com.gitee.sunchenbin.mybatis.actable.annotation.Table; +import com.gitee.sunchenbin.mybatis.actable.command.SaveOrUpdateDataCommand; import com.gitee.sunchenbin.mybatis.actable.dao.common.BaseMysqlCRUDMapper; @Transactional @@ -28,12 +29,12 @@ public class BaseMysqlCRUDManagerImpl implements BaseMysqlCRUDManager{ @Autowired private BaseMysqlCRUDMapper baseMysqlCRUDMapper; - public void save(T obj){ + public Integer save(T obj){ boolean isSave = true; Table tableName = obj.getClass().getAnnotation(Table.class); if ((tableName == null) || (tableName.name() == null || tableName.name() == "")) { log.error("必须使用model中的对象!"); - return; + return null; } Field[] declaredFields = getAllFields(obj); Map> tableMap = new HashMap>(); @@ -70,13 +71,17 @@ public class BaseMysqlCRUDManagerImpl implements BaseMysqlCRUDManager{ } if (isSave) { tableMap.put(tableName.name(), dataMap); + SaveOrUpdateDataCommand saveOrUpdateDataCommand = new SaveOrUpdateDataCommand(tableMap); // 执行保存操作 - baseMysqlCRUDMapper.save(tableMap); + baseMysqlCRUDMapper.save(saveOrUpdateDataCommand); + return saveOrUpdateDataCommand.getId(); }else{ dataMap.put(KEYFIELDMAP, keyFieldMap); tableMap.put(tableName.name(), dataMap); + SaveOrUpdateDataCommand saveOrUpdateDataCommand = new SaveOrUpdateDataCommand(tableMap); // 执行更新操作根据主键 - baseMysqlCRUDMapper.update(tableMap); + baseMysqlCRUDMapper.update(saveOrUpdateDataCommand); + return saveOrUpdateDataCommand.getId(); } } 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 bee758284b45c71de244532c9b5af32130b24e64..3e0fdda3c55fe3b246db5a463da19a6c3eceecf7 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 @@ -8,7 +8,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang3.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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 f4dc3d3d30f4c2840caa60576d722d8424424729..445a8d1b8e35b29d9f6a91f99da3b89dad4c26fc 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 @@ -1,14 +1,5 @@ package com.gitee.sunchenbin.mybatis.actable.manager.system; -import java.lang.reflect.Field; -import java.util.ArrayList; -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; @@ -16,14 +7,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.gitee.sunchenbin.mybatis.actable.annotation.Column; -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.OracleTypeConstant; import com.gitee.sunchenbin.mybatis.actable.dao.system.CreateMysqlTablesMapper; -import com.gitee.sunchenbin.mybatis.actable.utils.ClassTools; /** * 项目启动时自动扫描配置的目录中的model,根据配置的规则自动创建或更新表 diff --git a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/mapping/common/BaseMysqlCRUDMapper.xml b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/mapping/common/BaseMysqlCRUDMapper.xml index 9f1059958fdb5892fc629a3abd576573bc60fe3f..5147dd9b26d9830d0e8f838df3cd1a3ef1c6be52 100644 --- a/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/mapping/common/BaseMysqlCRUDMapper.xml +++ b/mybatis-enhance-actable/src/main/java/com/gitee/sunchenbin/mybatis/actable/mapping/common/BaseMysqlCRUDMapper.xml @@ -2,8 +2,8 @@ - - + + insert into `${key}`( @@ -21,12 +21,11 @@ ) - - - + + update `${key}` @@ -48,7 +47,6 @@ -