Ver código fonte

Merge remote-tracking branch 'origin/dev' into dev

yuxiaobin 7 anos atrás
pai
commit
c1cd63bef2

+ 28 - 0
CHANGELOG.md

@@ -1,6 +1,34 @@
 # CHANGELOG
 # CHANGELOG
 
 
 
 
+## [v2.1.7] 2017.12.11 代号:清风徐来 , 该版本号存在分页 asc bug 请改为 2.1.7-SNAPSHOT  
+- 枚举处理:基本类型,Number类型,String类型
+- IGDRW:源码注释错误,容易给人误导 注释错误问题
+- 炮灰 PR !42:添加分页构造方法重载 添加分页构造方法重载
+- 代码生成 > oracle > 解决超出最大游标的问题
+- fixed gitee IGNL9
+- k 神 一大波 testcase 来袭
+- 使用transient关键字去除Page中部分字段参与序列化
+- 去除无效日志
+- fix #IGI3H:selectBatchIds 参数改为Collection类型
+- bugfix for logic delete sql injector
+- 添加多个排序字段支持
+- isAsc 改为 ascSort 不忽略 size
+- fixed github #185:2.0.2版本 自增主键 批量插入问题 pr
+- 其他优化
+
+
+## [v2.1.6] 2017.11.22 代号:小秋秋之吻
+- 模块拆分为 support core generate 代码生成分离可选择依赖
+- 解决 gitee issue IFX30 拆分 mybatis-plus-support 包支持
+- 解决 gitee issue IGAPX 通用枚举 bigdecimal 类型映射
+- druid补充,填充字段修改
+- 修复 kotlin 代码生成部分逻辑 Bug
+- 合并 gitee pr 40 updateAllColumn****等方法排除fill = FieldFill.INSERT注释的字段 感谢 Elsif 
+- 构造模式设置 kotlin 修改
+- Sql 工具类反射实例优化
+- 其他优化
+
 ## [v2.1.6] 2017.11.22 代号:小秋秋之吻
 ## [v2.1.6] 2017.11.22 代号:小秋秋之吻
 - 模块拆分为 support core generate 代码生成分离可选择依赖
 - 模块拆分为 support core generate 代码生成分离可选择依赖
 - 解决 gitee issue IFX30 拆分 mybatis-plus-support 包支持
 - 解决 gitee issue IFX30 拆分 mybatis-plus-support 包支持

+ 1 - 1
build.gradle

@@ -39,7 +39,7 @@ ext {
 
 
 allprojects{
 allprojects{
     group = 'com.baomidou'
     group = 'com.baomidou'
-    version = '2.1.6'
+    version = '2.1.7-SNAPSHOT'
 }
 }
 
 
 
 

+ 29 - 7
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/EntityWrapperTest.java

@@ -127,7 +127,7 @@ public class EntityWrapperTest {
     @Test
     @Test
     public void testNoTSQL() {
     public void testNoTSQL() {
         /*
         /*
-		 * 实体 filter orderby
+         * 实体 filter orderby
 		 */
 		 */
         ew.setEntity(new User(1));
         ew.setEntity(new User(1));
         ew.addFilter("name={0}", "'123'").orderBy("id,name");
         ew.addFilter("name={0}", "'123'").orderBy("id,name");
@@ -138,8 +138,8 @@ public class EntityWrapperTest {
 
 
     @Test
     @Test
     public void testNoTSQL1() {
     public void testNoTSQL1() {
-		/*
-		 * 非 T-SQL 无实体查询
+        /*
+         * 非 T-SQL 无实体查询
 		 */
 		 */
         ew.addFilter("name={0}", "'123'").addFilterIfNeed(false, "status=?", "1");
         ew.addFilter("name={0}", "'123'").addFilterIfNeed(false, "status=?", "1");
         String sqlSegment = ew.originalSql();
         String sqlSegment = ew.originalSql();
@@ -149,8 +149,8 @@ public class EntityWrapperTest {
 
 
     @Test
     @Test
     public void testTSQL11() {
     public void testTSQL11() {
-		/*
-		 * 实体带查询使用方法 输出看结果
+        /*
+         * 实体带查询使用方法 输出看结果
 		 */
 		 */
         ew.setEntity(new User(1));
         ew.setEntity(new User(1));
         ew.where("name=?", "'zhangsan'").and("id=1").orNew("status=?", "0").or("status=1").notLike("nlike", "notvalue")
         ew.where("name=?", "'zhangsan'").and("id=1").orNew("status=?", "0").or("status=1").notLike("nlike", "notvalue")
@@ -325,8 +325,8 @@ public class EntityWrapperTest {
      */
      */
     @Test
     @Test
     public void testIsWhere() {
     public void testIsWhere() {
-		/*
-		 * 实体带where ifneed
+        /*
+         * 实体带where ifneed
 		 */
 		 */
         ew.setEntity(new User(1));
         ew.setEntity(new User(1));
         ew.setParamAlias("ceshi");
         ew.setParamAlias("ceshi");
@@ -408,4 +408,26 @@ public class EntityWrapperTest {
         Assert.assertEquals("ORDER BY id desc", wrapper.getSqlSegment());
         Assert.assertEquals("ORDER BY id desc", wrapper.getSqlSegment());
     }
     }
 
 
+    /**
+     * 测试 Condition orderBy
+     */
+    @Test
+    public void testConditionOrderBys() {
+        //空集合测试
+        List<String> orders = null;
+        Wrapper wrapper = Condition.create();
+        wrapper.orderAsc(orders);
+        Assert.assertNull(wrapper.getSqlSegment());
+        orders = new ArrayList<>(3);
+        wrapper.orderAsc(orders);
+        Assert.assertNull(wrapper.getSqlSegment());
+        orders.add("id1");
+        orders.add("id2");
+        orders.add("id3");
+        wrapper.orderAsc(orders);
+        Assert.assertEquals("ORDER BY id1 ASC, id2 ASC, id3 ASC", wrapper.getSqlSegment());
+        wrapper.orderDesc(orders);
+        Assert.assertEquals("ORDER BY id1 ASC, id2 ASC, id3 ASC, id1 DESC, id2 DESC, id3 DESC", wrapper.getSqlSegment());
+    }
+
 }
 }

+ 3 - 3
mybatis-plus-generate/src/main/java/com/baomidou/mybatisplus/generator/config/rules/NamingStrategy.java

@@ -41,11 +41,11 @@ public enum NamingStrategy {
             return "";
             return "";
         }
         }
         String tempName = name;
         String tempName = name;
-        StringBuilder result = new StringBuilder();
-        // 大写数字下划线组成转为小写
-        if (StringUtils.isCapitalMode(name)) {
+        // 大写数字下划线组成转为小写 , 允许混合模式转为小写
+        if (StringUtils.isCapitalMode(name) || StringUtils.isMixedMode(name)) {
             tempName = name.toLowerCase();
             tempName = name.toLowerCase();
         }
         }
+        StringBuilder result = new StringBuilder();
         // 用下划线将原始字符串分割
         // 用下划线将原始字符串分割
         String camels[] = tempName.split(ConstVal.UNDERLINE);
         String camels[] = tempName.split(ConstVal.UNDERLINE);
         for (String camel : camels) {
         for (String camel : camels) {

+ 2 - 2
mybatis-plus-support/src/main/java/com/baomidou/mybatisplus/mapper/AutoSqlInjector.java

@@ -670,7 +670,7 @@ public class AutoSqlInjector implements ISqlInjector {
     protected String sqlSelectObjsColumns(TableInfo table) {
     protected String sqlSelectObjsColumns(TableInfo table) {
         StringBuilder columns = new StringBuilder();
         StringBuilder columns = new StringBuilder();
         /*
         /*
-		 * 普通查询
+         * 普通查询
 		 */
 		 */
         columns.append("<choose><when test=\"ew != null and ew.sqlSelect != null\">${ew.sqlSelect}</when><otherwise>");
         columns.append("<choose><when test=\"ew != null and ew.sqlSelect != null\">${ew.sqlSelect}</when><otherwise>");
         // 主键处理
         // 主键处理
@@ -754,7 +754,7 @@ public class AutoSqlInjector implements ISqlInjector {
      * @return
      * @return
      */
      */
     protected String convertIfTag(boolean ignored, TableFieldInfo fieldInfo, String prefix, boolean close) {
     protected String convertIfTag(boolean ignored, TableFieldInfo fieldInfo, String prefix, boolean close) {
-		/* 忽略策略 */
+        /* 忽略策略 */
         FieldStrategy fieldStrategy = fieldInfo.getFieldStrategy();
         FieldStrategy fieldStrategy = fieldInfo.getFieldStrategy();
         if (fieldStrategy == FieldStrategy.IGNORED) {
         if (fieldStrategy == FieldStrategy.IGNORED) {
             if (ignored) {
             if (ignored) {

+ 3 - 3
mybatis-plus-support/src/main/java/com/baomidou/mybatisplus/mapper/SqlHelper.java

@@ -30,7 +30,6 @@ import com.baomidou.mybatisplus.plugins.Page;
 import com.baomidou.mybatisplus.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.toolkit.GlobalConfigUtils;
 import com.baomidou.mybatisplus.toolkit.GlobalConfigUtils;
 import com.baomidou.mybatisplus.toolkit.MapUtils;
 import com.baomidou.mybatisplus.toolkit.MapUtils;
-import com.baomidou.mybatisplus.toolkit.StringUtils;
 import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
 import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
 
 
 /**
 /**
@@ -194,8 +193,9 @@ public class SqlHelper {
             wrapper = Condition.create();
             wrapper = Condition.create();
         }
         }
         // 排序
         // 排序
-        if (page.isOpenSort() && StringUtils.isNotEmpty(page.getOrderByField())) {
-            wrapper.orderBy(page.getOrderByField(), page.isAsc());
+        if (page.isOpenSort()) {
+            wrapper.orderAsc(page.getAsc());
+            wrapper.orderDesc(page.getDesc());
         }
         }
         // MAP 参数查询
         // MAP 参数查询
         if (MapUtils.isNotEmpty(page.getCondition())) {
         if (MapUtils.isNotEmpty(page.getCondition())) {

+ 48 - 5
mybatis-plus-support/src/main/java/com/baomidou/mybatisplus/mapper/Wrapper.java

@@ -813,6 +813,25 @@ public abstract class Wrapper<T> implements Serializable {
         return this;
         return this;
     }
     }
 
 
+    /**
+     * <p>
+     * SQL中orderby关键字跟的条件语句,可根据变更动态排序
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param columns   SQL 中的 order by 语句,无需输入 Order By 关键字
+     * @param isAsc     是否为升序
+     * @return this
+     */
+    public Wrapper<T> orderBy(boolean condition, Collection<String> columns, boolean isAsc) {
+        if (condition && CollectionUtils.isNotEmpty(columns)) {
+            for (String column : columns) {
+                orderBy(condition, column, isAsc);
+            }
+        }
+        return this;
+    }
+
     /**
     /**
      * <p>
      * <p>
      * SQL中orderby关键字跟的条件语句,可根据变更动态排序
      * SQL中orderby关键字跟的条件语句,可根据变更动态排序
@@ -826,6 +845,30 @@ public abstract class Wrapper<T> implements Serializable {
         return orderBy(true, columns, isAsc);
         return orderBy(true, columns, isAsc);
     }
     }
 
 
+    /**
+     * <p>
+     * 批量根据ASC排序
+     * </p>
+     *
+     * @param columns 需要排序的集合
+     * @return this
+     */
+    public Wrapper<T> orderAsc(Collection<String> columns) {
+        return orderBy(true, columns, true);
+    }
+
+    /**
+     * <p>
+     * 批量根据DESC排序
+     * </p>
+     *
+     * @param columns 需要排序的集合
+     * @return this
+     */
+    public Wrapper<T> orderDesc(Collection<String> columns) {
+        return orderBy(true, columns, false);
+    }
+
     /**
     /**
      * <p>
      * <p>
      * LIKE条件语句,value中无需前后%
      * LIKE条件语句,value中无需前后%
@@ -1150,7 +1193,7 @@ public abstract class Wrapper<T> implements Serializable {
      *
      *
      * @param condition 拼接的前置条件
      * @param condition 拼接的前置条件
      * @param column    字段名称
      * @param column    字段名称
-     * @param value     匹配值 List集合
+     * @param value     匹配值 集合
      * @return this
      * @return this
      */
      */
     public Wrapper<T> in(boolean condition, String column, Collection<?> value) {
     public Wrapper<T> in(boolean condition, String column, Collection<?> value) {
@@ -1166,7 +1209,7 @@ public abstract class Wrapper<T> implements Serializable {
      * </p>
      * </p>
      *
      *
      * @param column 字段名称
      * @param column 字段名称
-     * @param value  匹配值 List集合
+     * @param value  匹配值 集合
      * @return this
      * @return this
      */
      */
     public Wrapper<T> in(String column, Collection<?> value) {
     public Wrapper<T> in(String column, Collection<?> value) {
@@ -1180,7 +1223,7 @@ public abstract class Wrapper<T> implements Serializable {
      *
      *
      * @param condition 拼接的前置条件
      * @param condition 拼接的前置条件
      * @param column    字段名称
      * @param column    字段名称
-     * @param value     匹配值 List集合
+     * @param value     匹配值 集合
      * @return this
      * @return this
      */
      */
     public Wrapper<T> notIn(boolean condition, String column, Collection<?> value) {
     public Wrapper<T> notIn(boolean condition, String column, Collection<?> value) {
@@ -1196,7 +1239,7 @@ public abstract class Wrapper<T> implements Serializable {
      * </p>
      * </p>
      *
      *
      * @param column 字段名称
      * @param column 字段名称
-     * @param value  匹配值 List集合
+     * @param value  匹配值 集合
      * @return this
      * @return this
      */
      */
     public Wrapper<T> notIn(String column, Collection<?> value) {
     public Wrapper<T> notIn(String column, Collection<?> value) {
@@ -1269,7 +1312,7 @@ public abstract class Wrapper<T> implements Serializable {
      * </p>
      * </p>
      *
      *
      * @param column 字段名称
      * @param column 字段名称
-     * @param value  集合List
+     * @param value  集合
      * @param isNot  是否为NOT IN操作
      * @param isNot  是否为NOT IN操作
      */
      */
     private String inExpression(String column, Collection<?> value, boolean isNot) {
     private String inExpression(String column, Collection<?> value, boolean isNot) {

+ 2 - 2
mybatis-plus-support/src/main/java/com/baomidou/mybatisplus/plugins/Page.java

@@ -56,9 +56,9 @@ public class Page<T> extends Pagination {
         this.setOrderByField(orderByField);
         this.setOrderByField(orderByField);
     }
     }
 
 
-    public Page(int current, int size, String orderByField, boolean isAsc) {
+    public Page(int current, int size, String orderByField, boolean ascSort) {
         this(current, size, orderByField);
         this(current, size, orderByField);
-        this.setAsc(isAsc);
+        this.setAscSort(ascSort);
     }
     }
 
 
     public List<T> getRecords() {
     public List<T> getRecords() {

+ 79 - 11
mybatis-plus-support/src/main/java/com/baomidou/mybatisplus/plugins/pagination/Pagination.java

@@ -16,6 +16,8 @@
 package com.baomidou.mybatisplus.plugins.pagination;
 package com.baomidou.mybatisplus.plugins.pagination;
 
 
 import java.io.Serializable;
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
 
 
 import org.apache.ibatis.session.RowBounds;
 import org.apache.ibatis.session.RowBounds;
 
 
@@ -55,7 +57,7 @@ public class Pagination extends RowBounds implements Serializable {
     /**
     /**
      * 每页显示条数,默认 10
      * 每页显示条数,默认 10
      */
      */
-    private transient int size = 10;
+    private int size = 10;
 
 
     /**
     /**
      * 总页数
      * 总页数
@@ -75,25 +77,45 @@ public class Pagination extends RowBounds implements Serializable {
     /**
     /**
      * 开启排序(默认 true) 只在代码逻辑判断 并不截取sql分析
      * 开启排序(默认 true) 只在代码逻辑判断 并不截取sql分析
      *
      *
-     * @see com.baomidou.mybatisplus.mapper.SqlHelper fillWrapper
+     * @see com.baomidou.mybatisplus.mapper.SqlHelper#fillWrapper
      **/
      **/
     private transient boolean openSort = true;
     private transient boolean openSort = true;
 
 
+
     /**
     /**
      * <p>
      * <p>
-     * SQL 排序 ORDER BY 字段,例如: id DESC(根据id倒序查询)
+     * SQL 排序 ASC 集合
      * </p>
      * </p>
+     */
+    private transient List<String> asc;
+    /**
      * <p>
      * <p>
-     * DESC 表示按倒序排序(即:从大到小排序)<br>
-     * ASC 表示按正序排序(即:从小到大排序)
+     * SQL 排序 DESC 集合
      * </p>
      * </p>
      */
      */
-    private transient String orderByField;
+    private transient List<String> desc;
 
 
     /**
     /**
      * 是否为升序 ASC( 默认: true )
      * 是否为升序 ASC( 默认: true )
+     *
+     * @see #asc
+     * @see #desc
+     */
+    private transient boolean ascSort = true;
+
+    /**
+     * <p>
+     * SQL 排序 ORDER BY 字段,例如: id DESC(根据id倒序查询)
+     * </p>
+     * <p>
+     * DESC 表示按倒序排序(即:从大到小排序)<br>
+     * ASC 表示按正序排序(即:从小到大排序)
+     *
+     * @see #asc
+     * @see #desc
+     * </p>
      */
      */
-    private transient boolean isAsc = true;
+    private transient String orderByField;
 
 
     public Pagination() {
     public Pagination() {
         super();
         super();
@@ -191,10 +213,19 @@ public class Pagination extends RowBounds implements Serializable {
         return this;
         return this;
     }
     }
 
 
+    /**
+     * @see #asc
+     * @see #desc
+     */
+    @Deprecated
     public String getOrderByField() {
     public String getOrderByField() {
         return orderByField;
         return orderByField;
     }
     }
 
 
+    /**
+     * @see #asc
+     * @see #desc
+     */
     public Pagination setOrderByField(String orderByField) {
     public Pagination setOrderByField(String orderByField) {
         if (StringUtils.isNotEmpty(orderByField)) {
         if (StringUtils.isNotEmpty(orderByField)) {
             this.orderByField = orderByField;
             this.orderByField = orderByField;
@@ -211,12 +242,49 @@ public class Pagination extends RowBounds implements Serializable {
         return this;
         return this;
     }
     }
 
 
-    public boolean isAsc() {
-        return isAsc;
+    public List<String> getAsc() {
+        return orders(ascSort, asc);
+    }
+
+    private List<String> orders(boolean condition, List<String> columns) {
+        if (condition && StringUtils.isNotEmpty(orderByField)) {
+            if (columns == null) {
+                columns = new ArrayList<>();
+            }
+            if (!columns.contains(orderByField)) {
+                columns.add(orderByField);
+            }
+        }
+        return columns;
     }
     }
 
 
-    public Pagination setAsc(boolean isAsc) {
-        this.isAsc = isAsc;
+    public void setAsc(List<String> asc) {
+        this.asc = asc;
+    }
+
+    public List<String> getDesc() {
+        return orders(!isAscSort(), desc);
+    }
+
+    public void setDesc(List<String> desc) {
+        this.desc = desc;
+    }
+
+    /**
+     * @see #asc
+     * @see #desc
+     */
+    @Deprecated
+    public boolean isAscSort() {
+        return ascSort;
+    }
+
+    /**
+     * @see #asc
+     * @see #desc
+     */
+    public Pagination setAscSort(boolean ascSort) {
+        this.ascSort = ascSort;
         return this;
         return this;
     }
     }
 
 

+ 34 - 3
mybatis-plus-support/src/main/java/com/baomidou/mybatisplus/toolkit/SqlUtils.java

@@ -15,6 +15,8 @@
  */
  */
 package com.baomidou.mybatisplus.toolkit;
 package com.baomidou.mybatisplus.toolkit;
 
 
+import java.util.List;
+
 import com.baomidou.mybatisplus.enums.SqlLike;
 import com.baomidou.mybatisplus.enums.SqlLike;
 import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
 import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
 import com.baomidou.mybatisplus.plugins.pagination.Pagination;
 import com.baomidou.mybatisplus.plugins.pagination.Pagination;
@@ -81,15 +83,44 @@ public class SqlUtils {
      * @return
      * @return
      */
      */
     public static String concatOrderBy(String originalSql, Pagination page, boolean orderBy) {
     public static String concatOrderBy(String originalSql, Pagination page, boolean orderBy) {
-        if (orderBy && StringUtils.isNotEmpty(page.getOrderByField()) && page.isOpenSort()) {
+        if (orderBy && page.isOpenSort()) {
             StringBuilder buildSql = new StringBuilder(originalSql);
             StringBuilder buildSql = new StringBuilder(originalSql);
-            buildSql.append(" ORDER BY ").append(page.getOrderByField());
-            buildSql.append(page.isAsc() ? " ASC " : " DESC ");
+            String ascStr = concatOrderBuilder(page.getAsc(), " ASC");
+            String descStr = concatOrderBuilder(page.getDesc(), " DESC");
+            if (StringUtils.isNotEmpty(ascStr) && StringUtils.isNotEmpty(descStr)) {
+                ascStr += ", ";
+            }
+            if (StringUtils.isNotEmpty(ascStr) || StringUtils.isNotEmpty(descStr)) {
+                buildSql.append(" ORDER BY ").append(ascStr).append(descStr);
+            }
             return buildSql.toString();
             return buildSql.toString();
         }
         }
         return originalSql;
         return originalSql;
     }
     }
 
 
+    /**
+     * 拼接多个排序方法
+     *
+     * @param columns
+     * @param orderWord
+     */
+    private static String concatOrderBuilder(List<String> columns, String orderWord) {
+        if (CollectionUtils.isNotEmpty(columns)) {
+            StringBuilder builder = new StringBuilder(16);
+            for (int i = 0; i < columns.size(); ) {
+                String cs = columns.get(i);
+                if (StringUtils.isNotEmpty(cs)) {
+                    builder.append(cs).append(orderWord);
+                }
+                if (++i != columns.size() && StringUtils.isNotEmpty(cs)) {
+                    builder.append(", ");
+                }
+            }
+            return builder.toString();
+        }
+        return StringUtils.EMPTY;
+    }
+
     /**
     /**
      * 格式sql
      * 格式sql
      *
      *

+ 12 - 0
mybatis-plus-support/src/main/java/com/baomidou/mybatisplus/toolkit/StringUtils.java

@@ -374,6 +374,18 @@ public class StringUtils {
         return null != word && word.matches("^[0-9A-Z/_]+$");
         return null != word && word.matches("^[0-9A-Z/_]+$");
     }
     }
 
 
+    /**
+     * <p>
+     * 是否为驼峰下划线混合命名
+     * </p>
+     *
+     * @param word 待判断字符串
+     * @return
+     */
+    public static boolean isMixedMode(String word) {
+        return Pattern.compile(".*[A-Z]+.*").matcher(word).matches() && Pattern.compile(".*[/_]+.*").matcher(word).matches();
+    }
+
     /**
     /**
      * <p>
      * <p>
      * Check if a String ends with a specified suffix.
      * Check if a String ends with a specified suffix.