写代码是没前途的 7 éve
szülő
commit
6576338655
100 módosított fájl, 8291 hozzáadás és 0 törlés
  1. 65 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/CrudTest.java
  2. 412 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/EntityWrapperTest.java
  3. 93 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/GlobalConfigurationTest.java
  4. 109 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/IdWorkerTest.java
  5. 71 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/MybatisMapperRefreshTest.java
  6. 38 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/StringUtilsTest.java
  7. 130 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/activerecord/ActiveRecordTest.java
  8. 173 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/generator/MysqlGenerator.java
  9. 142 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/generator/PostgreSQLGenerator.java
  10. 141 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/generator/SQLServerGenerator.java
  11. 122 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2LogicDeleteTest.java
  12. 264 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2MetaObjAndVersionAndOptLockTest.java
  13. 62 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2MetaObjectHandler.java
  14. 138 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2MetaObjectHandlerTest.java
  15. 45 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2Test.java
  16. 69 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserAddrJoinTest.java
  17. 107 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserAutoincrementTest.java
  18. 180 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserDateVersionTest.java
  19. 312 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserExtendsTest.java
  20. 312 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserNoOptLockTest.java
  21. 239 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserNoVersionTest.java
  22. 507 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserTest.java
  23. 58 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2uuidTest.java
  24. 41 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/DBConfig.java
  25. 64 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisConfigMetaObjOptLockConfig.java
  26. 66 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusConfig.java
  27. 63 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusLoginDeleteConfig.java
  28. 59 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusMetaObjConfig.java
  29. 55 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusNoOptLockConfig.java
  30. 64 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusSequenceConfig.java
  31. 20 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/ServiceConfig.java
  32. 20 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/ServiceSequenceConfig.java
  33. 44 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/SuperEntity.java
  34. 14 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/SuperMapper.java
  35. 29 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserDateVersionMapper.java
  36. 28 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserExtendsMapper.java
  37. 35 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserLogicDeleteMapper.java
  38. 83 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserMapper.java
  39. 28 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserMetaobjMapper.java
  40. 29 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserNoVersionMapper.java
  41. 28 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserSequenceExtendsMapper.java
  42. 28 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserSequenceMapper.java
  43. 58 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserVersionAndLogicDeleteMapper.java
  44. 16 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2uuidMapper.java
  45. 29 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/BaseIntVersionEntity.java
  46. 32 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/BaseSequenceEntity.java
  47. 32 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2Addr.java
  48. 104 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2User.java
  49. 115 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserDateVersion.java
  50. 45 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserIntVersionExtendTO.java
  51. 58 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserLogicDelete.java
  52. 113 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserMetaObj.java
  53. 110 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserNoVersion.java
  54. 22 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserSeq.java
  55. 61 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserSequence.java
  56. 50 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserSequenceExtendTO.java
  57. 117 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserVersionAndLogicDeleteEntity.java
  58. 59 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2uuid.java
  59. 16 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserExtendsService.java
  60. 16 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserLogicDeleteService.java
  61. 15 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserMetaobjService.java
  62. 31 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserNoVersionService.java
  63. 15 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserSequenceExtendsService.java
  64. 15 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserSequenceService.java
  65. 48 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserService.java
  66. 20 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserExtendsServiceImpl.java
  67. 29 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserLogicDeleteServiceImpl.java
  68. 20 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserMetaobjServiceImpl.java
  69. 36 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserNoVersionServiceImpl.java
  70. 20 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserSequenceExtendsServiceImpl.java
  71. 20 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserSequenceServiceImpl.java
  72. 86 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserServiceImpl.java
  73. 63 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/CircularLabelsTest.java
  74. 84 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/LogicDeleteTest.java
  75. 34 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/MyBaseMapper.java
  76. 59 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/MyMetaObjectHandler.java
  77. 67 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/MySqlInjector.java
  78. 70 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/NoXMLTest.java
  79. 55 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/ServiceImplTest.java
  80. 75 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/SqlRunnerTest.java
  81. 57 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/TransactionalTest.java
  82. 108 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/URPTest.java
  83. 334 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/UserMapperTest.java
  84. 77 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/NotPK.java
  85. 86 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/PhoneNumber.java
  86. 96 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/Role.java
  87. 91 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/Test.java
  88. 209 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/User.java
  89. 31 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/NotPKMapper.java
  90. 12 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/RoleMapper.java
  91. 39 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/TestMapper.java
  92. 74 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/UserMapper.java
  93. 33 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/service/IUserService.java
  94. 47 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/service/impl/UserServiceImpl.java
  95. 63 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/typehandler/PhoneTypeHandler.java
  96. 62 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/oracle/OracleDruidTest.java
  97. 62 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/oracle/OracleUserTest.java
  98. 115 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/oracle/TestSequserMapperTest.java
  99. 157 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/oracle/TestUserMapperTest.java
  100. 36 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/oracle/config/DruidOracleDBConfig.java

+ 65 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/CrudTest.java

@@ -0,0 +1,65 @@
+/**
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test;
+
+import java.io.InputStream;
+
+import org.apache.commons.dbcp2.BasicDataSource;
+import org.apache.ibatis.session.SqlSessionFactory;
+
+import com.baomidou.mybatisplus.MybatisSessionFactoryBuilder;
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.toolkit.GlobalConfigUtils;
+
+/**
+ * <p>
+ * CRUD 测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-06-18
+ */
+public class CrudTest {
+
+    public GlobalConfiguration globalConfiguration() {
+        GlobalConfiguration global = GlobalConfigUtils.defaults();
+        // global.setAutoSetDbType(true);
+        // 设置全局校验机制为FieldStrategy.Empty
+        global.setFieldStrategy(2);
+        return global;
+    }
+
+    public SqlSessionFactory sqlSessionFactory() {
+        return sqlSessionFactory("mysql-config.xml");
+    }
+
+    public SqlSessionFactory sqlSessionFactory(String configXml) {
+        GlobalConfiguration global = this.globalConfiguration();
+        BasicDataSource dataSource = new BasicDataSource();
+        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
+        dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/mybatis-plus?characterEncoding=UTF-8");
+        dataSource.setUsername("root");
+        dataSource.setPassword("521");
+        dataSource.setMaxTotal(1000);
+        GlobalConfigUtils.setMetaData(dataSource, global);
+        // 加载配置文件
+        InputStream inputStream = CrudTest.class.getClassLoader().getResourceAsStream(configXml);
+        MybatisSessionFactoryBuilder factoryBuilder = new MybatisSessionFactoryBuilder();
+        factoryBuilder.setGlobalConfig(global);
+        return factoryBuilder.build(inputStream);
+    }
+
+}

+ 412 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/EntityWrapperTest.java

@@ -0,0 +1,412 @@
+/**
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 EntityWrapperS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import com.baomidou.mybatisplus.entity.Columns;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.baomidou.mybatisplus.entity.Column;
+import com.baomidou.mybatisplus.enums.SqlLike;
+import com.baomidou.mybatisplus.mapper.Condition;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.mapper.Wrapper;
+import com.baomidou.mybatisplus.test.mysql.entity.User;
+
+/**
+ * <p>
+ * 条件查询测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2016-08-19
+ */
+public class EntityWrapperTest {
+
+
+    /*
+     * User 查询包装器
+     */
+    private EntityWrapper<User> ew = new EntityWrapper<>();
+
+    @Test
+    public void test() {
+        /*
+         * 无条件测试
+		 */
+        Assert.assertEquals("", ew.originalSql());
+    }
+
+    @Test
+    public void test11() {
+        /*
+         * 实体带where ifneed
+		 */
+        ew.setEntity(new User(1));
+        ew.where("name={0}", "'123'").addFilterIfNeed(false, "id=12");
+        String sqlSegment = ew.originalSql();
+        System.err.println("test11 = " + sqlSegment);
+        Assert.assertEquals("AND (name=?)", sqlSegment);
+    }
+
+    @Test
+    public void test12() {
+        /*
+         * 实体带where orderby
+		 */
+        ew.setEntity(new User(1));
+        ew.where("name={0}", "'123'").orderBy("id", false);
+        String sqlSegment = ew.originalSql();
+        System.err.println("test12 = " + sqlSegment);
+        Assert.assertEquals("AND (name=?)\nORDER BY id DESC", sqlSegment);
+    }
+
+    @Test
+    public void test13() {
+        /*
+         * 实体排序
+		 */
+        ew.setEntity(new User(1));
+        ew.orderBy("id", false);
+        String sqlSegment = ew.originalSql();
+        System.err.println("test13 = " + sqlSegment);
+        Assert.assertEquals("ORDER BY id DESC", sqlSegment);
+    }
+
+    @Test
+    public void test21() {
+        /*
+         * 无实体 where ifneed orderby
+		 */
+        ew.where("name={0}", "'123'").addFilterIfNeed(false, "id=1").orderBy("id");
+        String sqlSegment = ew.originalSql();
+        System.err.println("test21 = " + sqlSegment);
+        Assert.assertEquals("AND (name=?)\nORDER BY id", sqlSegment);
+    }
+
+    @Test
+    public void test22() {
+        ew.where("name={0}", "'123'").orderBy("id", false);
+        String sqlSegment = ew.originalSql();
+        System.err.println("test22 = " + sqlSegment);
+        Assert.assertEquals("AND (name=?)\nORDER BY id DESC", sqlSegment);
+    }
+
+    @Test
+    public void test23() {
+        /*
+         * 无实体查询,只排序
+		 */
+        ew.orderBy("id", false);
+        String sqlSegment = ew.originalSql();
+        System.err.println("test23 = " + sqlSegment);
+        Assert.assertEquals("ORDER BY id DESC", sqlSegment);
+    }
+
+    @Test
+    public void testNoTSQL() {
+		/*
+		 * 实体 filter orderby
+		 */
+        ew.setEntity(new User(1));
+        ew.addFilter("name={0}", "'123'").orderBy("id,name");
+        String sqlSegment = ew.originalSql();
+        System.err.println("testNoTSQL = " + sqlSegment);
+        Assert.assertEquals("AND (name=?)\nORDER BY id,name", sqlSegment);
+    }
+
+    @Test
+    public void testNoTSQL1() {
+		/*
+		 * 非 T-SQL 无实体查询
+		 */
+        ew.addFilter("name={0}", "'123'").addFilterIfNeed(false, "status=?", "1");
+        String sqlSegment = ew.originalSql();
+        System.err.println("testNoTSQL1 = " + sqlSegment);
+        Assert.assertEquals("AND (name=?)", sqlSegment);
+    }
+
+    @Test
+    public void testTSQL11() {
+		/*
+		 * 实体带查询使用方法 输出看结果
+		 */
+        ew.setEntity(new User(1));
+        ew.where("name=?", "'zhangsan'").and("id=1").orNew("status=?", "0").or("status=1").notLike("nlike", "notvalue")
+                .andNew("new=xx").like("hhh", "ddd").andNew("pwd=11").isNotNull("n1,n2").isNull("n3").groupBy("x1")
+                .groupBy("x2,x3").having("x1=11").having("x3=433").orderBy("dd").orderBy("d1,d2");
+        System.out.println(ew.originalSql());
+        Assert.assertEquals("AND (name=? AND id=1) \n" + "OR (status=? OR status=1 AND nlike NOT LIKE ?) \n"
+                + "AND (new=xx AND hhh LIKE ?) \n" + "AND (pwd=11 AND n1 IS NOT NULL AND n2 IS NOT NULL AND n3 IS NULL)\n"
+                + "GROUP BY x1, x2,x3\n" + "HAVING (x1=11 AND x3=433)\n" + "ORDER BY dd, d1,d2", ew.originalSql());
+    }
+
+    @Test
+    public void testNull() {
+        ew.orderBy(null);
+        String sqlPart = ew.originalSql();
+        Assert.assertEquals("", sqlPart);
+    }
+
+    @Test
+    public void testNull2() {
+        ew.like(null, null).where("aa={0}", "'bb'").orderBy(null);
+        String sqlPart = ew.originalSql();
+        Assert.assertEquals("AND (aa=?)", sqlPart);
+    }
+
+    /**
+     * 测试带单引号的值是否不会再次添加单引号
+     */
+    @Test
+    public void testNul14() {
+        ew.where("id={0}", "'11'").and("name={0}", 22);
+        String sqlPart = ew.originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals("AND (id=? AND name=?)", sqlPart);
+    }
+
+    /**
+     * 测试带不带单引号的值是否会自动添加单引号
+     */
+    @Test
+    public void testNul15() {
+        ew.where("id={0} and ids = {1}", "11", 22).and("name={0}", 222222222);
+        String sqlPart = ew.originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals("AND (id=? and ids = ? AND name=?)", sqlPart);
+    }
+
+    /**
+     * 测试EXISTS
+     */
+    @Test
+    public void testNul16() {
+        ew.notExists("(select * from user)");
+        String sqlPart = ew.originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals("AND ( NOT EXISTS ((select * from user)))", sqlPart);
+    }
+
+    /**
+     * 测试NOT IN
+     */
+    @Test
+    public void test17() {
+        List<String> list = new ArrayList<>();
+        list.add("'1'");
+        list.add("'2'");
+        list.add("'3'");
+        ew.notIn("test_type", list);
+        String sqlPart = ew.originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals("AND (test_type NOT IN (?,?,?))", sqlPart);
+    }
+
+    /**
+     * 测试IN
+     */
+    @Test
+    public void testNul18() {
+        List<Long> list = new ArrayList<>();
+        list.add(111111111L);
+        list.add(222222222L);
+        list.add(333333333L);
+        ew.in("test_type", list);
+        String sqlPart = ew.originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals("AND (test_type IN (?,?,?))", sqlPart);
+    }
+
+    /**
+     * 测试IN
+     */
+    @Test
+    public void test18() {
+        Set<Long> list = new TreeSet<>();
+        list.add(111111111L);
+        list.add(222222222L);
+        list.add(333333333L);
+        ew.in("test_type", list);
+        String sqlPart = ew.originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals("AND (test_type IN (?,?,?))", sqlPart);
+    }
+
+    /**
+     * 测试BETWEEN AND
+     */
+    @Test
+    public void testNul19() {
+        String val1 = "11";
+        String val2 = "33";
+        ew.between("test_type", val1, val2);
+        String sqlPart = ew.originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals("AND (test_type BETWEEN ? AND ?)", sqlPart);
+    }
+
+    /**
+     * 测试Escape
+     */
+    @Test
+    public void testEscape() {
+        String val1 = "'''";
+        String val2 = "\\";
+        ew.between("test_type", val1, val2);
+        String sqlPart = ew.originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals("AND (test_type BETWEEN ? AND ?)", sqlPart);
+    }
+
+    /**
+     * 测试Escape
+     */
+    @Test
+    public void testInstance() {
+        String val1 = "'''";
+        String val2 = "\\";
+        String sqlPart = Condition.create().between("test_type", val1, val2).originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals("AND (test_type BETWEEN ? AND ?)", sqlPart);
+    }
+
+    /**
+     * 测试Qbc
+     */
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testQbc() {
+        Map<String, Object> map = new TreeMap<>();
+        map.put("allEq1", "22");
+        map.put("allEq2", 3333);
+        map.put("allEq3", 66.99);
+        String sqlPart = Condition.create().gt("gt", 1).le("le", 2).lt("le", 3).ge("ge", 4).eq("eq", 5).allEq(map).originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals(
+                "AND (gt > ? AND le <= ? AND le < ? AND ge >= ? AND eq = ? AND allEq1 = ? AND allEq2 = ? AND allEq3 = ?)",
+                sqlPart);
+    }
+
+    /**
+     * 测试LIKE
+     */
+    @Test
+    public void testlike() {
+        String sqlPart = Condition.create().like("default", "default", SqlLike.DEFAULT).like("left", "left", SqlLike.LEFT)
+                .like("right", "right", SqlLike.RIGHT).originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals("AND (default LIKE ? AND left LIKE ? AND right LIKE ?)", sqlPart);
+    }
+
+    /**
+     * 测试isWhere
+     */
+    @Test
+    public void testIsWhere() {
+		/*
+		 * 实体带where ifneed
+		 */
+        ew.setEntity(new User(1));
+        ew.setParamAlias("ceshi");
+        ew.or("sql = {0}", "sql").like("default", "default", SqlLike.DEFAULT).like("left", "left", SqlLike.LEFT);
+        ew.in("aaabbbcc", "1,3,4");
+        String sqlPart = ew.in("bbb", Arrays.asList(new String[]{"a", "b", "c"})).like("right", "right", SqlLike.RIGHT).isWhere(true)
+                .eq("bool", true).between("ee", "1111", "222").originalSql();
+        System.out.println("sql ==> " + sqlPart);
+        Assert.assertEquals("WHERE (sql = ? AND default LIKE ? AND left LIKE ? AND aaabbbcc IN (?,?,?) AND bbb IN (?,?,?) AND right LIKE ? AND bool = ? AND ee BETWEEN ? AND ?)", sqlPart);
+        System.out.println(ew.getSqlSegment());
+    }
+
+    /**
+     * 测试 last
+     */
+    @Test
+    public void testLimit() {
+        ew.where("name={0}", "'123'").orderBy("id", false);
+        ew.last("limit 1,2");
+        String sqlSegment = ew.originalSql();
+        System.err.println("testLimit = " + sqlSegment);
+        Assert.assertEquals("AND (name=?)\nORDER BY id DESC limit 1,2", sqlSegment);
+    }
+
+    /**
+     * 测试 sqlselect
+     */
+    @Test
+    public void testSqlSelectStrings() {
+        EntityWrapper entityWrapper = new EntityWrapper();
+        entityWrapper.setSqlSelect("name", "age", "sex");
+        System.out.println(entityWrapper.getSqlSelect());
+        Assert.assertEquals("name,age,sex", entityWrapper.getSqlSelect());
+    }
+
+    /**
+     * 测试 sqlselect
+     */
+    @Test
+    public void testSqlSelect() {
+        EntityWrapper entityWrapper = new EntityWrapper();
+        // entityWrapper.setSqlSelect(Column.create().column("col").as("name"),null,Column.create(),Column.create().as("11"),Column.create().column("col"));
+        entityWrapper.setSqlSelect(Column.create().column("col").as("name"), null, Column.create(), Column.create().as("11"), Column.create().column("col"));
+        System.out.println(entityWrapper.getSqlSelect());
+        Assert.assertNotNull("col AS name,col", entityWrapper.getSqlSelect());
+
+    }
+
+    /**
+     * 测试 sqlselect
+     */
+    @Test
+    public void testSqlSelectColumns() {
+        EntityWrapper entityWrapper = new EntityWrapper();
+        Columns columns = Columns.create().column("name", "name1").column("age").column("sex", "sex1", false);
+        entityWrapper.setSqlSelect(columns);
+        System.out.println(entityWrapper.getSqlSelect());
+        Assert.assertEquals("name AS name1,age,sex AS sex1", entityWrapper.getSqlSelect());
+    }
+
+    /**
+     * 测试 EntityWrapper orderBy
+     */
+    @Test
+    public void testEntityWrapperOrderBy() {
+        EntityWrapper entityWrapper = new EntityWrapper();
+        entityWrapper.orderBy("id desc");
+        System.out.println(entityWrapper.getSqlSegment());
+        Assert.assertEquals("ORDER BY id desc", entityWrapper.getSqlSegment());
+    }
+
+    /**
+     * 测试 Condition orderBy
+     */
+    @Test
+    public void testConditionOrderBy() {
+        Wrapper wrapper = Condition.create().orderBy("id desc");
+        System.out.println(wrapper.getSqlSegment());
+        Assert.assertEquals("ORDER BY id desc", wrapper.getSqlSegment());
+    }
+
+}

+ 93 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/GlobalConfigurationTest.java

@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test;
+
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.ibatis.session.RowBounds;
+import org.apache.ibatis.session.SqlSession;
+import org.junit.Assert;
+
+import com.baomidou.mybatisplus.mapper.Condition;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.mapper.Wrapper;
+import com.baomidou.mybatisplus.test.mysql.entity.NotPK;
+import com.baomidou.mybatisplus.test.mysql.entity.Test;
+import com.baomidou.mybatisplus.test.mysql.mapper.NotPKMapper;
+import com.baomidou.mybatisplus.test.mysql.mapper.TestMapper;
+
+/**
+ * <p>
+ * 全局配置测试
+ * </p>
+ *
+ * @author Caratacus
+ * @Date 2016-12-22
+ */
+public class GlobalConfigurationTest extends CrudTest {
+
+    /**
+     * 全局配置测试
+     */
+    @org.junit.Test
+    public void testGlobalConfig() {
+        SqlSession session = this.sqlSessionFactory().openSession(false);
+        TestMapper testMapper = session.getMapper(TestMapper.class);
+        /*Wrapper type = Condition.instance().eq("id",1).or().in("type", new Object[]{1, 2, 3, 4, 5, 6});
+        List list = testMapper.selectList(type);
+        System.out.println(list.toString());*/
+        Test test = new Test();
+        test.setCreateTime(new Date());
+        // 开启全局校验字符串会忽略空字符串
+        test.setType("");
+        testMapper.insert(test);
+
+        SqlSession sqlSession = this.sqlSessionFactory().openSession(false);
+        NotPKMapper pkMapper = sqlSession.getMapper(NotPKMapper.class);
+        NotPK notPK = new NotPK();
+        notPK.setUuid(UUID.randomUUID().toString());
+        notPK.setIs(true);
+        notPK.setIsis(false);
+        int num = pkMapper.insert(notPK);
+        Assert.assertTrue(num > 0);
+        NotPK notPK1 = pkMapper.selectOne(notPK);
+        Assert.assertNotNull(notPK1);
+        List<NotPK> notPKS = pkMapper.selectPage(RowBounds.DEFAULT, new EntityWrapper<>(notPK));
+        System.out.println(notPKS);
+        Wrapper type = Condition.create().eq("type", 12121212);
+        Assert.assertFalse(type.isEmptyOfWhere());
+        System.out.println(type.getSqlSegment());
+        Assert.assertFalse(type.isEmptyOfWhere());
+        pkMapper.selectPage(RowBounds.DEFAULT, type);
+        NotPK notPK2 = null;
+        try {
+            notPK2 = pkMapper.selectById("1");
+        } catch (Exception e) {
+            System.out.println("因为没有主键,所以没有注入该方法");
+        }
+        Assert.assertNull(notPK2);
+        int count = pkMapper.selectCount(Condition.EMPTY);
+        pkMapper.selectList(Condition.create().orderBy("uuid"));
+        pkMapper.selectList(Condition.create().eq("uuid", "uuid").orderBy("uuid"));
+        Assert.assertTrue(count > 0);
+        int deleteCount = pkMapper.delete(null);
+        Assert.assertTrue(deleteCount > 0);
+        sqlSession.commit();
+    }
+
+}

+ 109 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/IdWorkerTest.java

@@ -0,0 +1,109 @@
+/**
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CompletionService;
+import java.util.concurrent.ExecutorCompletionService;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.junit.Assert;
+
+import com.baomidou.mybatisplus.test.plugins.RandomUtils;
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+
+/**
+ * <p>
+ * IdWorker 并发测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2016-08-01
+ */
+public class IdWorkerTest {
+
+    public static void main(String[] args) throws Exception {
+        IdWorkerTest test = new IdWorkerTest();
+        test.test();
+        test.test1();
+        test.test2();
+    }
+
+    //@Test
+    public void test() throws Exception {
+        int count = 1000;
+        System.err.println("共有" + count + "个数参与测试");
+
+        ExecutorService executorService = Executors.newFixedThreadPool(20);
+        final List<Long> results = new ArrayList<>();
+        CompletionService<Long> cs = new ExecutorCompletionService<>(executorService);
+        for (int i = 1; i < count; i++) {
+            cs.submit(new Callable<Long>() {
+                public Long call() throws Exception {
+                    Thread.sleep(RandomUtils.nextInt(1, 2000));
+                    return IdWorker.getId();
+                }
+            });
+        }
+        for (int i = 0; i < count; i++) {
+            Future<Long> future = executorService.submit(new Callable<Long>() {
+                @Override
+                public Long call() throws Exception {
+                    return IdWorker.getId();
+                }
+            });
+            results.add(future.get());
+        }
+        executorService.shutdown();
+        HashSet<Long> set = new HashSet<>(results);
+        // 判断是否有重复
+        Assert.assertEquals(count, set.size());
+        int odd = 0;
+        int even = 0;
+        for (Long id : results) {
+            if (id % 2 != 0) {
+                odd++;
+            } else {
+                even++;
+            }
+        }
+        System.err.println("奇数:" + odd);
+        System.err.println("偶数:" + even);
+    }
+
+    //@Test
+    public void test1() throws Exception {
+        // 毫秒内并发
+        for (int i = 0; i < 1000; i++) {
+            System.out.println(IdWorker.getId());
+        }
+    }
+
+
+    //@Test
+    public void test2() throws Exception {
+        // 随机尾数
+        for (int i = 0; i < 1000; i++) {
+            Thread.sleep(10);
+            System.out.println(IdWorker.getId());
+        }
+    }
+}

+ 71 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/MybatisMapperRefreshTest.java

@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test;
+
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+
+import com.baomidou.mybatisplus.plugins.pagination.Pagination;
+import com.baomidou.mybatisplus.spring.MybatisMapperRefresh;
+import com.baomidou.mybatisplus.test.mysql.mapper.UserMapper;
+import com.baomidou.mybatisplus.toolkit.SystemClock;
+
+/**
+ * <p>
+ * 切莫用于生产环境(后果自负)<br>
+ * Mybatis 映射文件热加载(发生变动后自动重新加载).<br>
+ * 方便开发时使用,不用每次修改xml文件后都要去重启应用.<br>
+ * </p>
+ *
+ * @author nieqiurong
+ * @Date 2016-08-25
+ */
+public class MybatisMapperRefreshTest extends CrudTest {
+
+
+    /**
+     * 测试 Mybatis XML 修改自动刷新
+     */
+    public static void main(String[] args) throws Exception {
+        Resource[] resource = new ClassPathResource[]{new ClassPathResource("mysql/UserMapper.xml")};
+        SqlSessionFactory sessionFactory = new CrudTest().sqlSessionFactory();
+        new MybatisMapperRefresh(sessionFactory, 0, 5, true);
+        boolean isReturn = false;
+        SqlSession session = null;
+        while (!isReturn) {
+            try {
+                session = sessionFactory.openSession();
+                UserMapper userMapper = session.getMapper(UserMapper.class);
+                userMapper.selectListRow(new Pagination(1, 10));
+                resource[0].getFile().setLastModified(SystemClock.now());
+                session.commit();
+                session.close();
+                Thread.sleep(5000);
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                if (session != null) {
+                    session.close();
+                }
+                Thread.sleep(5000);
+            }
+        }
+        System.exit(0);
+    }
+
+}

+ 38 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/StringUtilsTest.java

@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.baomidou.mybatisplus.toolkit.StringUtils;
+
+/**
+ * <p>
+ * 字符串工具类测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-06-27
+ */
+public class StringUtilsTest {
+
+    @Test
+    public void removePrefixAfterPrefixToLower() {
+        Assert.assertEquals("user", StringUtils.removePrefixAfterPrefixToLower("isUser", 2));
+        Assert.assertEquals("userInfo", StringUtils.removePrefixAfterPrefixToLower("isUserInfo", 2));
+    }
+}

+ 130 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/activerecord/ActiveRecordTest.java

@@ -0,0 +1,130 @@
+/**
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.activerecord;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.jdbc.SQL;
+
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.CrudTest;
+import com.baomidou.mybatisplus.test.mysql.entity.Test;
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
+
+/**
+ * <p>
+ * ActiveRecord 测试
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2016-10-11
+ */
+public class ActiveRecordTest extends CrudTest {
+
+    @org.junit.Test
+    public void test() {
+        TableInfoHelper.initSqlSessionFactory(this.sqlSessionFactory());
+        // 保存一条记录
+        Test t1 = new Test();
+        t1.setType("test10");
+        boolean rlt = t1.insert();
+        print(" ar save=" + rlt + ", id=" + t1.getId());
+
+        // 根据ID更新
+        t1.setType("t1001");
+        rlt = t1.updateAllColumnById();
+        print(" ar updateAllColumnById:" + rlt);
+
+        t1.setType("t1023");
+        rlt = t1.updateById();
+        print(" ar updateById:" + rlt);
+
+        // 更新 SQL
+        Test t11 = new Test();
+        t11.setType("123");
+        rlt = t11.update("id={0}", t1.getId());
+        print("update sql=" + rlt);
+
+        // 查询 SQL
+        Test t10 = t1.selectOne("id={0}", t1.getId());
+        print("selectOne=" + t10.getType());
+
+        // 插入OR更新
+        t1.setType("t1021");
+        rlt = t1.insertOrUpdate();
+        print(" ar saveOrUpdate:" + rlt);
+
+        // 根据ID查询
+        Test t2 = t1.selectById();
+        print(" t2 = " + t2.toString());
+        t2.setId(IdWorker.getId());
+        t2.insert();
+
+        // 查询所有
+        List<Test> tl = t2.selectAll();
+        for (Test t : tl) {
+            print("selectAll=" + t.toString());
+        }
+
+        // 查询总记录数
+        print(" count=" + t2.selectCount(null));
+
+        // 翻页查询
+        Page<Test> page = new Page<>(0, 10);
+        page = t2.selectPage(page, null);
+        print(page.toString());
+
+        // 根据ID删除
+        rlt = t2.deleteById();
+        print("deleteById=" + rlt + ", id=" + t2.getId());
+
+        // 执行 SQL 查询总数
+        List<Map<String, Object>> ul = t2.sql().selectList(new SQL() {
+            {
+                SELECT("*");
+                FROM("test");
+                WHERE("type='t1021'");
+            }
+        }.toString());
+        System.err.println("selectList SQL:");
+        for (Map<String, Object> map : ul) {
+            System.err.println(map);
+        }
+
+        // 根据ID查询
+        Test t20 = t2.selectById();
+        print("t2 删除后是否存在?" + (null != t20));
+
+        // 删除 SQL
+        rlt = t2.delete("type={0}", "t1021");
+        System.err.println("delete sql=" + rlt);
+    }
+
+    /*
+     * 慢点打印
+     */
+    private static void print(String text) {
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        System.err.println(text);
+    }
+
+}

+ 173 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/generator/MysqlGenerator.java

@@ -0,0 +1,173 @@
+/**
+ * Copyright (c) 2011-2016, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.generator;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.baomidou.mybatisplus.enums.FieldFill;
+import com.baomidou.mybatisplus.generator.AutoGenerator;
+import com.baomidou.mybatisplus.generator.InjectionConfig;
+import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
+import com.baomidou.mybatisplus.generator.config.FileOutConfig;
+import com.baomidou.mybatisplus.generator.config.GlobalConfig;
+import com.baomidou.mybatisplus.generator.config.PackageConfig;
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
+import com.baomidou.mybatisplus.generator.config.TemplateConfig;
+import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
+import com.baomidou.mybatisplus.generator.config.po.TableFill;
+import com.baomidou.mybatisplus.generator.config.po.TableInfo;
+import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
+import com.baomidou.mybatisplus.generator.config.rules.DbType;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+
+/**
+ * <p>
+ * 代码生成器演示
+ * </p>
+ *
+ * @author hubin
+ * @date 2016-12-01
+ */
+public class MysqlGenerator {
+
+    /**
+     * <p>
+     * MySQL 生成演示
+     * </p>
+     */
+    public static void main(String[] args) {
+        // 自定义需要填充的字段
+        List<TableFill> tableFillList = new ArrayList<>();
+        tableFillList.add(new TableFill("ASDD_SS", FieldFill.INSERT_UPDATE));
+
+        // 代码生成器
+        AutoGenerator mpg = new AutoGenerator().setGlobalConfig(
+                // 全局配置
+                new GlobalConfig()
+                        .setOutputDir("/develop/code/")//输出目录
+                        .setFileOverride(true)// 是否覆盖文件
+                        .setActiveRecord(true)// 开启 activeRecord 模式
+                        .setEnableCache(false)// XML 二级缓存
+                        .setBaseResultMap(true)// XML ResultMap
+                        .setBaseColumnList(true)// XML columList
+                        //.setKotlin(true) 是否生成 kotlin 代码
+                        .setAuthor("Yanghu")
+                // 自定义文件命名,注意 %s 会自动填充表实体属性!
+                // .setMapperName("%sDao")
+                // .setXmlName("%sDao")
+                // .setServiceName("MP%sService")
+                // .setServiceImplName("%sServiceDiy")
+                // .setControllerName("%sAction")
+        ).setDataSource(
+                // 数据源配置
+                new DataSourceConfig()
+                        .setDbType(DbType.MYSQL)// 数据库类型
+                        .setTypeConvert(new MySqlTypeConvert() {
+                            // 自定义数据库表字段类型转换【可选】
+                            @Override
+                            public DbColumnType processTypeConvert(String fieldType) {
+                                System.out.println("转换类型:" + fieldType);
+                                // if ( fieldType.toLowerCase().contains( "tinyint" ) ) {
+                                //    return DbColumnType.BOOLEAN;
+                                // }
+                                return super.processTypeConvert(fieldType);
+                            }
+                        })
+                        .setDriverName("com.mysql.jdbc.Driver")
+                        .setUsername("root")
+                        .setPassword("123456")
+                        .setUrl("jdbc:mysql://127.0.0.1:3306/mybatis-plus?characterEncoding=utf8")
+        ).setStrategy(
+                // 策略配置
+                new StrategyConfig()
+                        // .setCapitalMode(true)// 全局大写命名
+                        // .setDbColumnUnderline(true)//全局下划线命名
+                        .setTablePrefix(new String[]{"bmd_", "mp_"})// 此处可以修改为您的表前缀
+                        .setNaming(NamingStrategy.underline_to_camel)// 表名生成策略
+                        // .setInclude(new String[] { "user" }) // 需要生成的表
+                        // .setExclude(new String[]{"test"}) // 排除生成的表
+                        // 自定义实体父类
+                        // .setSuperEntityClass("com.baomidou.demo.TestEntity")
+                        // 自定义实体,公共字段
+                        .setSuperEntityColumns(new String[]{"test_id"})
+                        .setTableFillList(tableFillList)
+                // 自定义 mapper 父类
+                // .setSuperMapperClass("com.baomidou.demo.TestMapper")
+                // 自定义 service 父类
+                // .setSuperServiceClass("com.baomidou.demo.TestService")
+                // 自定义 service 实现类父类
+                // .setSuperServiceImplClass("com.baomidou.demo.TestServiceImpl")
+                // 自定义 controller 父类
+                // .setSuperControllerClass("com.baomidou.demo.TestController")
+                // 【实体】是否生成字段常量(默认 false)
+                // public static final String ID = "test_id";
+                // .setEntityColumnConstant(true)
+                // 【实体】是否为构建者模型(默认 false)
+                // public User setName(String name) {this.name = name; return this;}
+                // .setEntityBuilderModel(true)
+                // 【实体】是否为lombok模型(默认 false)<a href="https://projectlombok.org/">document</a>
+                // .setEntityLombokModel(true)
+                // Boolean类型字段是否移除is前缀处理
+                // .setEntityBooleanColumnRemoveIsPrefix(true)
+                // .setRestControllerStyle(true)
+                // .setControllerMappingHyphenStyle(true)
+        ).setPackageInfo(
+                // 包配置
+                new PackageConfig()
+                        .setModuleName("test")
+                        .setParent("com.baomidou")// 自定义包路径
+                        .setController("controller")// 这里是控制器包名,默认 web
+        ).setCfg(
+                // 注入自定义配置,可以在 VM 中使用 cfg.abc 设置的值
+                new InjectionConfig() {
+                    @Override
+                    public void initMap() {
+                        Map<String, Object> map = new HashMap<>();
+                        map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-mp");
+                        this.setMap(map);
+                    }
+                }.setFileOutConfigList(Collections.<FileOutConfig>singletonList(new FileOutConfig("/templates/mapper.xml.vm") {
+                    // 自定义输出文件目录
+                    @Override
+                    public String outputFile(TableInfo tableInfo) {
+                        return "/develop/code/xml/" + tableInfo.getEntityName() + ".xml";
+                    }
+                }))
+        ).setTemplate(
+                // 关闭默认 xml 生成,调整生成 至 根目录
+                new TemplateConfig().setXml(null)
+                // 自定义模板配置,模板可以参考源码 /mybatis-plus/src/main/resources/template 使用 copy
+                // 至您项目 src/main/resources/template 目录下,模板名称也可自定义如下配置:
+                // .setController("...");
+                // .setEntity("...");
+                // .setMapper("...");
+                // .setXml("...");
+                // .setService("...");
+                // .setServiceImpl("...");
+        );
+
+        // 执行生成
+        mpg.execute();
+
+        // 打印注入设置,这里演示模板里面怎么获取注入内容【可无】
+        System.err.println(mpg.getCfg().getMap().get("abc"));
+    }
+
+}

+ 142 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/generator/PostgreSQLGenerator.java

@@ -0,0 +1,142 @@
+package com.baomidou.mybatisplus.test.generator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.baomidou.mybatisplus.generator.AutoGenerator;
+import com.baomidou.mybatisplus.generator.InjectionConfig;
+import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
+import com.baomidou.mybatisplus.generator.config.FileOutConfig;
+import com.baomidou.mybatisplus.generator.config.GlobalConfig;
+import com.baomidou.mybatisplus.generator.config.PackageConfig;
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
+import com.baomidou.mybatisplus.generator.config.converts.OracleTypeConvert;
+import com.baomidou.mybatisplus.generator.config.po.TableInfo;
+import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
+import com.baomidou.mybatisplus.generator.config.rules.DbType;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+
+/**
+ * <p>
+ * PostgreSQLGenerator
+ * </p>
+ *
+ * @author nieqiurong
+ * @Date 2016/12/25
+ */
+public class PostgreSQLGenerator {
+
+    public static void main(String[] args) {
+        AutoGenerator mpg = new AutoGenerator();
+
+        // 全局配置
+        GlobalConfig gc = new GlobalConfig();
+        gc.setOutputDir("D://");
+        gc.setFileOverride(true);
+        gc.setActiveRecord(true);// 开启 activeRecord 模式
+        gc.setEnableCache(false);// XML 二级缓存
+        gc.setBaseResultMap(true);// XML ResultMap
+        gc.setBaseColumnList(false);// XML columList
+        //gc.setKotlin(true) 是否生成 kotlin 代码
+        gc.setAuthor("hubin");
+
+        // 自定义文件命名,注意 %s 会自动填充表实体属性!
+        // gc.setMapperName("%sDao");
+        // gc.setXmlName("%sDao");
+        // gc.setServiceName("MP%sService");
+        // gc.setServiceImplName("%sServiceDiy");
+        // gc.setControllerName("%sAction");
+        mpg.setGlobalConfig(gc);
+
+        // 数据源配置
+        DataSourceConfig dsc = new DataSourceConfig();
+        dsc.setSchemaname("public");// 指定 SCHEMA
+        dsc.setDbType(DbType.POSTGRE_SQL);
+        dsc.setTypeConvert(new OracleTypeConvert() {
+            // 自定义数据库表字段类型转换【可选】
+            @Override
+            public DbColumnType processTypeConvert(String fieldType) {
+                System.out.println("转换类型:" + fieldType);
+                return super.processTypeConvert(fieldType);
+            }
+        });
+        dsc.setDriverName("org.postgresql.Driver");
+        dsc.setUsername("postgres");
+        dsc.setPassword("521");
+        dsc.setUrl("jdbc:postgresql://localhost:5432/mybatis-plus");
+        mpg.setDataSource(dsc);
+
+        // 策略配置
+        StrategyConfig strategy = new StrategyConfig();
+        // strategy.setCapitalMode(true);// 全局大写命名
+        // strategy.setDbColumnUnderline(true);//全局下划线命名
+        strategy.setTablePrefix(new String[]{"bmd_", "mp_"});// 此处可以修改为您的表前缀
+        strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
+        // strategy.setInclude(new String[] { "user" }); // 需要生成的表
+        // strategy.setExclude(new String[]{"test"}); // 排除生成的表
+        // 自定义实体父类
+        // strategy.setSuperEntityClass("com.baomidou.demo.TestEntity");
+        // 自定义实体,公共字段
+        // strategy.setSuperEntityColumns(new String[] { "test_id", "age" });
+        // 自定义 mapper 父类
+        // strategy.setSuperMapperClass("com.baomidou.demo.TestMapper");
+        // 自定义 service 父类
+        // strategy.setSuperServiceClass("com.baomidou.demo.TestService");
+        // 自定义 service 实现类父类
+        // strategy.setSuperServiceImplClass("com.baomidou.demo.TestServiceImpl");
+        // 自定义 controller 父类
+        // strategy.setSuperControllerClass("com.baomidou.demo.TestController");
+        // 【实体】是否生成字段常量(默认 false)
+        // public static final String ID = "test_id";
+        // strategy.setEntityColumnConstant(true);
+        // 【实体】是否为构建者模型(默认 false)
+        // public User setName(String name) {this.name = name; return this;}
+        // strategy.setEntityBuliderModel(true);
+        mpg.setStrategy(strategy);
+
+        // 包配置
+        PackageConfig pc = new PackageConfig();
+        pc.setModuleName("test");
+        pc.setParent("com.baomidou");// 自定义包路径
+        pc.setController("controller");// 这里是控制器包名,默认 web
+        mpg.setPackageInfo(pc);
+
+        // 注入自定义配置,可以在 VM 中使用 cfg.abc 设置的值
+        InjectionConfig cfg = new InjectionConfig() {
+            @Override
+            public void initMap() {
+                Map<String, Object> map = new HashMap<>();
+                map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-mp");
+                this.setMap(map);
+            }
+        };
+        List<FileOutConfig> focList = new ArrayList<>();
+        focList.add(new FileOutConfig("/templates/entity.java.vm") {
+            @Override
+            public String outputFile(TableInfo tableInfo) {
+                // 自定义输入文件名称
+                return "D://my_" + tableInfo.getEntityName() + ".java";
+            }
+        });
+        cfg.setFileOutConfigList(focList);
+        mpg.setCfg(cfg);
+
+        // 自定义模板配置,模板可以参考源码 /mybatis-plus/src/main/resources/template 使用 copy
+        // 至您项目 src/main/resources/template 目录下,模板名称也可自定义如下配置:
+        // TemplateConfig tc = new TemplateConfig();
+        // tc.setController("...");
+        // tc.setEntity("...");
+        // tc.setMapper("...");
+        // tc.setXml("...");
+        // tc.setService("...");
+        // tc.setServiceImpl("...");
+        // mpg.setTemplate(tc);
+        // 执行生成
+        mpg.execute();
+        // 打印注入设置
+        System.err.println(mpg.getCfg().getMap().get("abc"));
+    }
+
+}

+ 141 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/generator/SQLServerGenerator.java

@@ -0,0 +1,141 @@
+package com.baomidou.mybatisplus.test.generator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.baomidou.mybatisplus.generator.AutoGenerator;
+import com.baomidou.mybatisplus.generator.InjectionConfig;
+import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
+import com.baomidou.mybatisplus.generator.config.FileOutConfig;
+import com.baomidou.mybatisplus.generator.config.GlobalConfig;
+import com.baomidou.mybatisplus.generator.config.PackageConfig;
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
+import com.baomidou.mybatisplus.generator.config.converts.SqlServerTypeConvert;
+import com.baomidou.mybatisplus.generator.config.po.TableInfo;
+import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
+import com.baomidou.mybatisplus.generator.config.rules.DbType;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+
+/**
+ * <p>
+ * SQLServerGenerator
+ * </p>
+ *
+ * @author nieqiurong
+ * @Date 2016/12/25
+ */
+public class SQLServerGenerator {
+
+    public static void main(String[] args) {
+        AutoGenerator mpg = new AutoGenerator();
+
+        // 全局配置
+        GlobalConfig gc = new GlobalConfig();
+        gc.setOutputDir("D://");
+        gc.setFileOverride(true);
+        gc.setActiveRecord(true);// 开启 activeRecord 模式
+        gc.setEnableCache(false);// XML 二级缓存
+        gc.setBaseResultMap(true);// XML ResultMap
+        gc.setBaseColumnList(false);// XML columList
+        //gc.setKotlin(true) 是否生成 kotlin 代码
+        gc.setAuthor("nieqiurong");
+
+        // 自定义文件命名,注意 %s 会自动填充表实体属性!
+        // gc.setMapperName("%sDao");
+        // gc.setXmlName("%sDao");
+        // gc.setServiceName("MP%sService");
+        // gc.setServiceImplName("%sServiceDiy");
+        // gc.setControllerName("%sAction");
+        mpg.setGlobalConfig(gc);
+
+        // 数据源配置
+        DataSourceConfig dsc = new DataSourceConfig();
+        dsc.setDbType(DbType.SQL_SERVER);
+        dsc.setTypeConvert(new SqlServerTypeConvert() {
+            // 自定义数据库表字段类型转换【可选】
+            @Override
+            public DbColumnType processTypeConvert(String fieldType) {
+                System.out.println("转换类型:" + fieldType);
+                return super.processTypeConvert(fieldType);
+            }
+        });
+        dsc.setDriverName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
+        dsc.setUsername("sa");
+        dsc.setPassword("nieqiuqiu");
+        dsc.setUrl("jdbc:sqlserver://192.168.1.105:1433;databaseName=mybatis-plus");
+        mpg.setDataSource(dsc);
+
+        // 策略配置
+        StrategyConfig strategy = new StrategyConfig();
+        // strategy.setCapitalMode(true);// 全局大写命名
+        // strategy.setDbColumnUnderline(true);//全局下划线命名
+        strategy.setTablePrefix(new String[]{"bmd_", "mp_"});// 此处可以修改为您的表前缀
+        strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
+        // strategy.setInclude(new String[] { "user" }); // 需要生成的表
+        // strategy.setExclude(new String[]{"test"}); // 排除生成的表
+        // 自定义实体父类
+        // strategy.setSuperEntityClass("com.baomidou.demo.TestEntity");
+        // 自定义实体,公共字段
+        // strategy.setSuperEntityColumns(new String[] { "test_id", "age" });
+        // 自定义 mapper 父类
+        // strategy.setSuperMapperClass("com.baomidou.demo.TestMapper");
+        // 自定义 service 父类
+        // strategy.setSuperServiceClass("com.baomidou.demo.TestService");
+        // 自定义 service 实现类父类
+        // strategy.setSuperServiceImplClass("com.baomidou.demo.TestServiceImpl");
+        // 自定义 controller 父类
+        // strategy.setSuperControllerClass("com.baomidou.demo.TestController");
+        // 【实体】是否生成字段常量(默认 false)
+        // public static final String ID = "test_id";
+        // strategy.setEntityColumnConstant(true);
+        // 【实体】是否为构建者模型(默认 false)
+        // public User setName(String name) {this.name = name; return this;}
+        // strategy.setEntityBuliderModel(true);
+        mpg.setStrategy(strategy);
+
+        // 包配置
+        PackageConfig pc = new PackageConfig();
+        pc.setModuleName("test");
+        pc.setParent("com.baomidou");// 自定义包路径
+        pc.setController("controller");// 这里是控制器包名,默认 web
+        mpg.setPackageInfo(pc);
+
+        // 注入自定义配置,可以在 VM 中使用 cfg.abc 设置的值
+        InjectionConfig cfg = new InjectionConfig() {
+            @Override
+            public void initMap() {
+                Map<String, Object> map = new HashMap<>();
+                map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-mp");
+                this.setMap(map);
+            }
+        };
+        List<FileOutConfig> focList = new ArrayList<>();
+        focList.add(new FileOutConfig("/templates/entity.java.vm") {
+            @Override
+            public String outputFile(TableInfo tableInfo) {
+                // 自定义输入文件名称
+                return "D://my_" + tableInfo.getEntityName() + ".java";
+            }
+        });
+        cfg.setFileOutConfigList(focList);
+        mpg.setCfg(cfg);
+
+        // 自定义模板配置,模板可以参考源码 /mybatis-plus/src/main/resources/template 使用 copy
+        // 至您项目 src/main/resources/template 目录下,模板名称也可自定义如下配置:
+        // TemplateConfig tc = new TemplateConfig();
+        // tc.setController("...");
+        // tc.setEntity("...");
+        // tc.setMapper("...");
+        // tc.setXml("...");
+        // tc.setService("...");
+        // tc.setServiceImpl("...");
+        // mpg.setTemplate(tc);
+        // 执行生成
+        mpg.execute();
+        // 打印注入设置
+        System.err.println(mpg.getCfg().getMap().get("abc"));
+    }
+
+}

+ 122 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2LogicDeleteTest.java

@@ -0,0 +1,122 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+
+import com.baomidou.mybatisplus.mapper.Condition;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.h2.config.ServiceConfig;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserLogicDelete;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserLogicDeleteService;
+
+/**
+ * <p>
+ * H2LogicDeleteTest
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/15
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {ServiceConfig.class})
+public class H2LogicDeleteTest extends H2Test {
+
+    @BeforeClass
+    public static void init() throws SQLException, IOException {
+        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
+        context.register(ServiceConfig.class);
+        context.refresh();
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            String createTableSql = readFile("user.ddl.sql");
+            Statement stmt = conn.createStatement();
+            stmt.execute(createTableSql);
+            stmt.execute("truncate table h2user");
+            executeSql(stmt, "user.insert.sql");
+            conn.commit();
+        }
+    }
+
+    @Autowired
+    private IH2UserLogicDeleteService userService;
+
+    @Test
+    public void testInsert() {
+        H2UserLogicDelete user = new H2UserLogicDelete();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        user.setVersion(1);
+        userService.insert(user);
+        Long id = user.getId();
+        Assert.assertNotNull(id);
+        user.setDesc("Caratacus");
+        userService.insertOrUpdate(user);
+        System.out.println("************************************");
+        System.out.println("*********" + user.getVersion());
+        System.out.println("************************************");
+        user = new H2UserLogicDelete();
+        user.setId(id);
+        EntityWrapper<H2UserLogicDelete> ew = new EntityWrapper<>(user);
+        List<H2UserLogicDelete> list = userService.selectList(ew);
+        System.out.println("************************************");
+        System.out.println("*********" + list.size());
+        System.out.println("************************************");
+        H2UserLogicDelete userFromDB = userService.selectById(user.getId());
+        Assert.assertEquals("Caratacus", userFromDB.getDesc());
+        Assert.assertEquals(1, userFromDB.getVersion().intValue());
+        Page page = new Page();
+
+        page.setOrderByField("desc");
+        userService.selectPage(page, Condition.create().eq("desc", "111"));
+        userService.deleteById(id);
+        list = userService.selectList(ew);
+        System.out.println("************************************");
+        System.out.println("*********" + list.size());
+        System.out.println("************************************");
+    }
+
+    @Test
+    public void testLogicDeleted() {
+        H2UserLogicDelete user = new H2UserLogicDelete();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        user.setVersion(-1);
+        userService.insert(user);
+        Long id = user.getId();
+        Assert.assertNotNull(id);
+        Assert.assertNotNull(userService.selectList(Condition.create().orderBy("age")));
+        H2UserLogicDelete userFromDB = userService.selectById(user.getId());
+        Assert.assertNull(userFromDB);
+    }
+
+    @Test
+    public void testDelete(){
+        H2UserLogicDelete user = new H2UserLogicDelete();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        user.setVersion(1);
+        userService.insert(user);
+        Long id = user.getId();
+        Assert.assertNotNull(id);
+        Assert.assertTrue(userService.deleteById(id));
+        H2UserLogicDelete fromDB = userService.selectByIdMy(id);
+        Assert.assertNotNull(fromDB);
+        System.out.println(fromDB);
+    }
+}

+ 264 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2MetaObjAndVersionAndOptLockTest.java

@@ -0,0 +1,264 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+
+import com.baomidou.mybatisplus.mapper.Condition;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.h2.config.DBConfig;
+import com.baomidou.mybatisplus.test.h2.config.MybatisConfigMetaObjOptLockConfig;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserVersionAndLogicDeleteMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserVersionAndLogicDeleteEntity;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/29
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {DBConfig.class, MybatisConfigMetaObjOptLockConfig.class})
+public class H2MetaObjAndVersionAndOptLockTest extends H2Test {
+
+    @BeforeClass
+    public static void initDB() throws SQLException, IOException {
+        @SuppressWarnings("resource")
+        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
+        context.register(DBConfig.class);
+        context.register(MybatisConfigMetaObjOptLockConfig.class);
+        context.refresh();
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            String createTableSql = readFile("user.ddl.sql");
+            Statement stmt = conn.createStatement();
+            stmt.execute(createTableSql);
+            stmt.execute("truncate table h2user");
+            executeSql(stmt, "user.insert.sql");
+            conn.commit();
+        }
+    }
+
+    @Autowired
+    H2UserVersionAndLogicDeleteMapper userMapper;
+
+    @Test
+    public void testInsert() {
+        Long id = 991L;
+        H2UserVersionAndLogicDeleteEntity user = new H2UserVersionAndLogicDeleteEntity();
+        user.setId(id);
+        user.setName("991");
+        user.setAge(91);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userMapper.insertAllColumn(user);
+
+        H2UserVersionAndLogicDeleteEntity userDB = userMapper.selectById(id);
+        Assert.assertEquals(null, userDB.getTestDate());
+
+        userDB.setName("991");
+        userMapper.updateById(userDB);
+
+        userDB = userMapper.selectById(id);
+        Assert.assertEquals("991", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperNoDateVersion() {
+        Long id = 992L;
+        H2UserVersionAndLogicDeleteEntity user = new H2UserVersionAndLogicDeleteEntity();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userMapper.insertAllColumn(user);
+
+        H2UserVersionAndLogicDeleteEntity userDB = userMapper.selectById(id);
+
+        H2UserVersionAndLogicDeleteEntity updUser = new H2UserVersionAndLogicDeleteEntity();
+        updUser.setName("999");
+
+        userMapper.update(updUser, new EntityWrapper<>(userDB));
+
+        userDB = userMapper.selectById(id);
+        Assert.assertEquals("999", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByIdWithDateVersion() {
+        Long id = 994L;
+        H2UserVersionAndLogicDeleteEntity user = new H2UserVersionAndLogicDeleteEntity();
+        user.setId(id);
+        user.setName("994");
+        user.setAge(91);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.DAY_OF_MONTH, -1);
+        user.setTestDate(cal.getTime());
+        userMapper.insertAllColumn(user);
+
+        System.out.println("before update: testDate=" + user.getTestDate());
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
+        H2UserVersionAndLogicDeleteEntity userDB = userMapper.selectById(id);
+
+        Assert.assertNotNull(userDB.getTestDate());
+        String originalDateVersionStr = sdf.format(cal.getTime());
+        Assert.assertEquals(originalDateVersionStr, sdf.format(userDB.getTestDate()));
+
+        userDB.setName("991");
+        userMapper.updateById(userDB);
+        userDB = userMapper.selectById(id);
+        Assert.assertEquals("991", userDB.getName());
+        Date versionDate = userDB.getTestDate();
+        System.out.println("after update: testDate=" + versionDate);
+        String versionDateStr = sdf.format(versionDate);
+        Assert.assertEquals(sdf.format(new Date()), versionDateStr);
+
+        Assert.assertNotEquals(originalDateVersionStr, versionDateStr);
+
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperWithDateVersion() {
+        Long id = 993L;
+        H2UserVersionAndLogicDeleteEntity user = new H2UserVersionAndLogicDeleteEntity();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.DAY_OF_MONTH, -1);
+        user.setTestDate(cal.getTime());
+        userMapper.insertAllColumn(user);
+
+        H2UserVersionAndLogicDeleteEntity userDB = userMapper.selectById(id);
+
+        H2UserVersionAndLogicDeleteEntity updUser = new H2UserVersionAndLogicDeleteEntity();
+        updUser.setName("999");
+        userDB.setVersion(null);
+        userMapper.update(updUser, new EntityWrapper<>(userDB));
+
+        System.out.println("before update: testDate=" + userDB.getTestDate());
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
+
+        userDB = userMapper.selectById(id);
+        Assert.assertEquals("999", userDB.getName());
+
+        Date versionDate = userDB.getTestDate();
+        System.out.println("after update: testDate=" + versionDate);
+        String versionDateStr = sdf.format(versionDate);
+        Assert.assertEquals(sdf.format(new Date()), versionDateStr);
+    }
+
+
+    @Test
+    public void testLogicDeleted() {
+        H2UserVersionAndLogicDeleteEntity user = new H2UserVersionAndLogicDeleteEntity();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        user.setVersion(-1);
+        userMapper.insert(user);
+        Long id = user.getId();
+        Assert.assertNotNull(id);
+        Assert.assertNotNull(userMapper.selectList(Condition.create().orderBy("age")));
+        H2UserVersionAndLogicDeleteEntity userFromDB = userMapper.selectById(user.getId());
+        Assert.assertNull(userFromDB);
+    }
+
+    @Test
+    public void testInsertMy() {
+        String name = "自定义insert";
+        int version = 1;
+        int row = userMapper.myInsertWithNameVersion(name, version);
+        Assert.assertEquals(1, row);
+    }
+
+    @Test
+    public void testInsertObjectWithParam() {
+        String name = "自定义insert带Param注解";
+        int version = 1;
+        H2UserVersionAndLogicDeleteEntity user = new H2UserVersionAndLogicDeleteEntity();
+        user.setName(name);
+        user.setVersion(version);
+        int row = userMapper.myInsertWithParam(user);
+        Assert.assertEquals(1, row);
+    }
+
+    @Test
+    public void testInsertObjectWithoutParam() {
+        String name = "自定义insert带Param注解";
+        int version = 1;
+        H2UserVersionAndLogicDeleteEntity user = new H2UserVersionAndLogicDeleteEntity();
+        user.setName(name);
+        user.setVersion(version);
+        int row = userMapper.myInsertWithoutParam(user);
+        Assert.assertEquals(1, row);
+    }
+
+    @Test
+    public void testUpdateMy() {
+        Long id = 10087L;
+        H2UserVersionAndLogicDeleteEntity user = new H2UserVersionAndLogicDeleteEntity();
+        user.setId(id);
+        user.setName("myUpdate");
+        user.setVersion(1);
+        userMapper.insert(user);
+
+        H2UserVersionAndLogicDeleteEntity dbUser = userMapper.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("myUpdate", dbUser.getName());
+
+        Assert.assertEquals(1, userMapper.myUpdateWithNameId(id, "updateMy"));
+
+        dbUser = userMapper.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("updateMy", dbUser.getName());
+        Assert.assertEquals(1, user.getVersion().intValue());
+    }
+
+
+    @Test
+    public void testCondition() {
+        Page<H2UserVersionAndLogicDeleteEntity> page = new Page<>(1, 3);
+        Map<String, Object> condition = new HashMap<>();
+        condition.put("test_type", 1);
+        page.setCondition(condition);
+        List<H2UserVersionAndLogicDeleteEntity> pageResult = userMapper.selectPage(page, new EntityWrapper<H2UserVersionAndLogicDeleteEntity>());
+        for (H2UserVersionAndLogicDeleteEntity u : pageResult) {
+            System.out.println(u);
+        }
+
+    }
+}

+ 62 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2MetaObjectHandler.java

@@ -0,0 +1,62 @@
+package com.baomidou.mybatisplus.test.h2;
+/**
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+
+import java.sql.Timestamp;
+
+import org.apache.ibatis.reflection.MetaObject;
+
+import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
+
+/**
+ * <p>
+ * 测试,自定义元对象字段填充控制器,实现公共字段自动写入
+ * </p>
+ *
+ * @author hubin
+ * @Date 2017-06-25
+ */
+public class H2MetaObjectHandler extends MetaObjectHandler {
+
+    /**
+     * 测试 user 表 name 字段为空自动填充
+     */
+    public void insertFill(MetaObject metaObject) {
+        System.out.println("*************************");
+        System.out.println("insert fill");
+        System.out.println("*************************");
+
+        // 测试下划线
+        Object testType = this.getFieldValByName("testType", metaObject);
+        System.out.println("testType=" + testType);
+        if (testType == null) {
+            //测试实体没有的字段,配置在公共填充,不应该set到实体里面
+            this.setFieldValByName("testType1", 3, metaObject);
+            this.setFieldValByName("testType", 3, metaObject);
+        }
+    }
+
+    @Override
+    public void updateFill(MetaObject metaObject) {
+        System.out.println("*************************");
+        System.out.println("update fill");
+        System.out.println("*************************");
+        //测试实体没有的字段,配置在公共填充,不应该set到实体里面
+        this.setFieldValByName("lastUpdatedDt1", new Timestamp(System.currentTimeMillis()), metaObject);
+        this.setFieldValByName("lastUpdatedDt", new Timestamp(System.currentTimeMillis()), metaObject);
+    }
+}
+

+ 138 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2MetaObjectHandlerTest.java

@@ -0,0 +1,138 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserMetaobjMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserMetaObj;
+
+/**
+ * <p>
+ * 测试元对象填充器
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/5/31
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:h2/spring-test-h2-metaobj.xml"})
+public class H2MetaObjectHandlerTest extends H2Test {
+
+    @Autowired
+    private H2UserMetaobjMapper userMapper;
+
+    @BeforeClass
+    public static void initDB() throws SQLException, IOException {
+        @SuppressWarnings("resource")
+        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:h2/spring-test-h2-metaobj.xml");
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            String createTableSql = readFile("user.ddl.sql");
+            Statement stmt = conn.createStatement();
+            stmt.execute(createTableSql);
+            stmt.execute("truncate table h2user");
+            executeSql(stmt, "user.insert.sql");
+            conn.commit();
+        }
+    }
+
+    @Test
+    public void testMetaObjectHandler() {
+        H2UserMetaObj user = new H2UserMetaObj();
+        user.setName("metaobjtest");
+        user.setVersion(1);
+        user.setAge(12);
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.DAY_OF_MONTH, -1);
+        user.setLastUpdatedDt(new Timestamp(cal.getTimeInMillis()));
+        user.setDesc("abc");
+        userMapper.insert(user);
+        System.out.println("before update: getLastUpdatedDt=" + user.getLastUpdatedDt());
+        Assert.assertNotNull(userMapper.selectById(user.getId()).getTestType());
+
+        user.setName("999");
+        userMapper.updateById(user);
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
+        Long id = user.getId();
+        H2UserMetaObj userDB = userMapper.selectById(id);
+
+        //MyMetaObjectHandler.insertFill() : set default testType value=3
+        Assert.assertEquals(3, userDB.getTestType().intValue());
+        Assert.assertEquals("999", userDB.getName());
+
+        Date lastUpdatedDt = userDB.getLastUpdatedDt();
+        System.out.println("after update: testDate=" + lastUpdatedDt);
+        String versionDateStr = sdf.format(lastUpdatedDt);
+        //MyMetaObjectHandler.updateFill() : set lastUpdatedDt=currentTimestamp
+        Assert.assertEquals(sdf.format(new Date()), versionDateStr);//before update: lastUpdatedDt=currentTimestamp-1day
+    }
+
+    @Test
+    public void testMetaObjectHandlerNullInsert4Update() {
+        H2UserMetaObj user = new H2UserMetaObj();
+        user.setName("metaobjtest");
+        user.setVersion(1);
+        user.setAge(12);
+        user.setDesc("abc");
+        userMapper.insert(user);
+        System.out.println("before update: getLastUpdatedDt=" + user.getLastUpdatedDt());
+        Assert.assertNotNull(userMapper.selectById(user.getId()).getTestType());
+        user.setName("999");
+        userMapper.updateById(user);
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
+        Long id = user.getId();
+        H2UserMetaObj userDB = userMapper.selectById(id);
+        Date lastUpdatedDt = userDB.getLastUpdatedDt();
+        System.out.println("after update: testDate=" + lastUpdatedDt);
+        String versionDateStr = sdf.format(lastUpdatedDt);
+        //MyMetaObjectHandler.updateFill() : set lastUpdatedDt=currentTimestamp
+        Assert.assertEquals(sdf.format(new Date()), versionDateStr);//before update: lastUpdatedDt=currentTimestamp-1day
+    }
+
+
+    @Test
+    public void testInsertMy() {
+        String name = "testInsertMy";
+        int version = 1;
+        int row = userMapper.myInsertWithNameVersion(name, version);
+        Assert.assertEquals(1, row);
+    }
+
+    @Test
+    public void testUpdateMy() {
+        H2UserMetaObj user = new H2UserMetaObj();
+        user.setName("myUpdate");
+        user.setVersion(1);
+        userMapper.insert(user);
+        Long id = user.getId();
+        H2UserMetaObj dbUser = userMapper.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("myUpdate", dbUser.getName());
+
+        Assert.assertEquals(1, userMapper.myUpdateWithNameId(id, "updateMy"));
+
+        dbUser = userMapper.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("updateMy", dbUser.getName());
+        Assert.assertEquals(1, user.getVersion().intValue());
+    }
+
+}

+ 45 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2Test.java

@@ -0,0 +1,45 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * <p>
+ * Mybatis Plus H2 Junit Test
+ * </p>
+ *
+ * @author hubin
+ * @since 2017-06-15
+ */
+public class H2Test {
+
+    public static void executeSql(Statement stmt, String sqlFilename) throws SQLException, IOException {
+        String filePath = H2Test.class.getResource("/h2/" + sqlFilename).getPath();
+        try (
+                BufferedReader reader = new BufferedReader(new FileReader(filePath))
+        ) {
+            String line;
+            while ((line = reader.readLine()) != null) {
+                stmt.execute(line.replace(";", ""));
+            }
+        }
+    }
+
+    public static String readFile(String filename) {
+        StringBuilder builder = new StringBuilder();
+        String filePath = H2UserNoOptLockTest.class.getResource("/h2/" + filename).getPath();
+        try (
+                BufferedReader reader = new BufferedReader(new FileReader(filePath))
+        ) {
+            String line;
+            while ((line = reader.readLine()) != null)
+                builder.append(line).append(" ");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return builder.toString();
+    }
+}

+ 69 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserAddrJoinTest.java

@@ -0,0 +1,69 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2Addr;
+
+/**
+ * <p>
+ * Mybatis Plus H2 Junit Test
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:h2/spring-test-h2.xml"})
+public class H2UserAddrJoinTest extends H2Test {
+
+    @Autowired
+    private H2UserMapper userMapper;
+
+    @BeforeClass
+    public static void initDB() throws SQLException, IOException {
+        @SuppressWarnings("resource")
+        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:h2/spring-test-h2.xml");
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            Statement stmt = conn.createStatement();
+            stmt.execute(readFile("user.ddl.sql"));
+            stmt.execute("truncate table h2user");
+            stmt.execute(readFile("addr.ddl.sql"));
+            stmt.execute("truncate table h2address");
+            executeSql(stmt, "user.insert.sql");
+            executeSql(stmt, "addr.insert.sql");
+            conn.commit();
+        }
+    }
+
+    @Test
+    public void testJoinTableWithoutPagination() {
+        List<H2Addr> addrList = userMapper.getAddrListByUserId(101L);
+        Assert.assertEquals(5, addrList.size());
+    }
+
+    @Test
+    public void testJoinTableWithPagination() {
+        List<H2Addr> addrList = userMapper.getAddrListByUserIdPage(101L, new Page<H2Addr>(0, 3));
+        Assert.assertEquals(3, addrList.size());
+    }
+
+}

+ 107 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserAutoincrementTest.java

@@ -0,0 +1,107 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserMetaobjMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserMetaObj;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserMetaobjService;
+
+/**
+ * <p>
+ * Mybatis Plus H2 Junit Test
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:h2/spring-test-h2.xml"})
+public class H2UserAutoincrementTest extends H2Test {
+
+    @Autowired
+    private H2UserMetaobjMapper userMapper;
+
+    @Autowired
+    IH2UserMetaobjService userService;
+
+    @BeforeClass
+    public static void initDB() throws SQLException, IOException {
+        @SuppressWarnings("resource")
+        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:h2/spring-test-h2.xml");
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            String createTableSql = readFile("user.ddl.sql");
+            Statement stmt = conn.createStatement();
+            stmt.execute(createTableSql);
+            stmt.execute("truncate table h2user");
+            executeSql(stmt, "user.insert.sql");
+            conn.commit();
+        }
+    }
+
+    @Test
+    public void testInsert() {
+        H2UserMetaObj user = new H2UserMetaObj();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        Assert.assertEquals(1, userMapper.insert(user).intValue());
+        Long id1 = user.getId();
+        Assert.assertNotNull(id1);
+        user.setDesc("Caratacus");
+        Assert.assertEquals(1, userMapper.updateById(user).intValue());
+        H2UserMetaObj userFromDB = userMapper.selectById(id1);
+        Assert.assertEquals("Caratacus", userFromDB.getDesc());
+
+        H2UserMetaObj user2 = new H2UserMetaObj();
+        user2.setAge(2);
+        Assert.assertEquals(1, userMapper.insert(user2).intValue());
+        Long userId2 = user2.getId();
+        Assert.assertEquals(id1.intValue() + 1, userId2.intValue());
+    }
+
+
+    @Test
+    public void testInsertMy() {
+        String name = "testInsertMy";
+        int version = 1;
+        int row = userMapper.myInsertWithNameVersion(name, version);
+        Assert.assertEquals(1, row);
+    }
+
+    @Test
+    public void testUpdateMy() {
+        H2UserMetaObj user = new H2UserMetaObj();
+        user.setName("myUpdate");
+        user.setVersion(1);
+        userMapper.insert(user);
+        Long id = user.getId();
+        H2UserMetaObj dbUser = userMapper.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("myUpdate", dbUser.getName());
+
+        Assert.assertEquals(1, userMapper.myUpdateWithNameId(id, "updateMy"));
+
+        dbUser = userMapper.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("updateMy", dbUser.getName());
+        Assert.assertEquals(1, user.getVersion().intValue());
+
+    }
+
+}

+ 180 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserDateVersionTest.java

@@ -0,0 +1,180 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserDateVersionMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserDateVersion;
+
+/**
+ * <p>
+ * Mybatis Plus H2 Junit Test
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:h2/spring-test-h2.xml"})
+public class H2UserDateVersionTest extends H2Test {
+
+    @Autowired
+    private H2UserDateVersionMapper userMapper;
+
+    @BeforeClass
+    public static void initDB() throws SQLException, IOException {
+        @SuppressWarnings("resource")
+        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:h2/spring-test-h2.xml");
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            String createTableSql = readFile("user.ddl.sql");
+            Statement stmt = conn.createStatement();
+            stmt.execute(createTableSql);
+            stmt.execute("truncate table h2user");
+            executeSql(stmt, "user.insert.sql");
+            conn.commit();
+        }
+    }
+
+
+    @Test
+    public void testUpdateByIdNoDateVersion() {
+        Long id = 991L;
+        H2UserDateVersion user = new H2UserDateVersion();
+        user.setId(id);
+        user.setName("991");
+        user.setAge(91);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userMapper.insertAllColumn(user);
+
+        H2UserDateVersion userDB = userMapper.selectById(id);
+        Assert.assertEquals(null, userDB.getTestDate());
+
+        userDB.setName("991");
+        userMapper.updateById(userDB);
+
+        userDB = userMapper.selectById(id);
+        Assert.assertEquals("991", userDB.getName());
+    }
+
+
+    @Test
+    public void testUpdateByEntityWrapperNoDateVersion() {
+        Long id = 992L;
+        H2UserDateVersion user = new H2UserDateVersion();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userMapper.insertAllColumn(user);
+
+        H2UserDateVersion userDB = userMapper.selectById(id);
+
+        H2UserDateVersion updUser = new H2UserDateVersion();
+        updUser.setName("999");
+
+        userMapper.update(updUser, new EntityWrapper<>(userDB));
+
+        userDB = userMapper.selectById(id);
+        Assert.assertEquals("999", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByIdWithDateVersion() {
+        Long id = 994L;
+        H2UserDateVersion user = new H2UserDateVersion();
+        user.setId(id);
+        user.setName("994");
+        user.setAge(91);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.DAY_OF_MONTH, -1);
+        user.setTestDate(cal.getTime());
+        userMapper.insertAllColumn(user);
+
+        System.out.println("before update: testDate=" + user.getTestDate());
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
+        H2UserDateVersion userDB = userMapper.selectById(id);
+
+        Assert.assertNotNull(userDB.getTestDate());
+        String originalDateVersionStr = sdf.format(cal.getTime());
+        Assert.assertEquals(originalDateVersionStr, sdf.format(userDB.getTestDate()));
+
+        userDB.setName("991");
+        userMapper.updateById(userDB);
+        userDB = userMapper.selectById(id);
+        Assert.assertEquals("991", userDB.getName());
+        Date versionDate = userDB.getTestDate();
+        System.out.println("after update: testDate=" + versionDate);
+        String versionDateStr = sdf.format(versionDate);
+        Assert.assertEquals(sdf.format(new Date()), versionDateStr);
+
+        Assert.assertNotEquals(originalDateVersionStr, versionDateStr);
+
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperWithDateVersion() {
+        Long id = 993L;
+        H2UserDateVersion user = new H2UserDateVersion();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.DAY_OF_MONTH, -1);
+        user.setTestDate(cal.getTime());
+        userMapper.insertAllColumn(user);
+
+        H2UserDateVersion userDB = userMapper.selectById(id);
+
+        H2UserDateVersion updUser = new H2UserDateVersion();
+        updUser.setName("999");
+        userDB.setVersion(null);
+        userMapper.update(updUser, new EntityWrapper<>(userDB));
+
+        System.out.println("before update: testDate=" + userDB.getTestDate());
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
+
+        userDB = userMapper.selectById(id);
+        Assert.assertEquals("999", userDB.getName());
+
+        Date versionDate = userDB.getTestDate();
+        System.out.println("after update: testDate=" + versionDate);
+        String versionDateStr = sdf.format(versionDate);
+        Assert.assertEquals(sdf.format(new Date()), versionDateStr);
+    }
+
+
+}

+ 312 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserExtendsTest.java

@@ -0,0 +1,312 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.h2.config.ServiceConfig;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserIntVersionExtendTO;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserExtendsService;
+
+/**
+ * <p>
+ * #328 实体继承属性测试
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {ServiceConfig.class})
+public class H2UserExtendsTest extends H2Test {
+
+    @Autowired
+    IH2UserExtendsService userService;
+
+    @BeforeClass
+    public static void init() throws SQLException, IOException {
+        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
+        context.register(ServiceConfig.class);
+        context.refresh();
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            String createTableSql = readFile("user.ddl.sql");
+            Statement stmt = conn.createStatement();
+            stmt.execute(createTableSql);
+            stmt.execute("truncate table h2user");
+            executeSql(stmt, "user.insert.sql");
+            conn.commit();
+        }
+    }
+
+    @Test
+    public void testInsert() {
+        H2UserIntVersionExtendTO user = new H2UserIntVersionExtendTO();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        userService.insert(user);
+        Assert.assertNotNull(user.getId());
+        user.setDesc("Caratacus");
+        userService.insertOrUpdate(user);
+        H2UserIntVersionExtendTO userFromDB = userService.selectById(user.getId());
+        Assert.assertEquals("Caratacus", userFromDB.getDesc());
+    }
+
+    @Test
+    public void testUpdate() {
+        H2UserIntVersionExtendTO user = new H2UserIntVersionExtendTO();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        userService.insert(user);
+        Long id = user.getId();
+        Assert.assertNotNull(id);
+        user.setDesc("Caratacus");
+        userService.insertOrUpdate(user);
+        H2UserIntVersionExtendTO userFromDB = userService.selectById(id);
+        Assert.assertEquals("Caratacus", userFromDB.getDesc());
+
+        user = new H2UserIntVersionExtendTO();
+        user.setId(id);
+        user.setDesc("Caratacus2");
+        userService.updateById(user);
+        userFromDB = userService.selectById(id);
+        Assert.assertEquals("Caratacus2", userFromDB.getDesc());
+        Assert.assertEquals(new BigDecimal("9.99"), userFromDB.getPrice());
+    }
+
+
+    @Test
+    public void testDelete() {
+        H2UserIntVersionExtendTO user = new H2UserIntVersionExtendTO();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.91"));
+        userService.insert(user);
+        Long userId = user.getId();
+        Assert.assertNotNull(userId);
+        Assert.assertNotNull(userService.selectById(userId));
+        userService.deleteById(userId);
+        Assert.assertNull(userService.selectById(userId));
+    }
+
+    @Test
+    public void testSelectPage() {
+        Page<H2UserIntVersionExtendTO> page = userService.selectPage(new Page<H2UserIntVersionExtendTO>(1, 3));
+        Assert.assertEquals(3, page.getRecords().size());
+    }
+
+    @Test
+    public void testUpdateByIdOptLock() {
+        Long id = 991L;
+        H2UserIntVersionExtendTO user = new H2UserIntVersionExtendTO();
+        user.setId(id);
+        user.setName("991");
+        user.setAge(91);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2UserIntVersionExtendTO userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        userDB.setName("992");
+        userService.updateById(userDB);
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(2, userDB.getVersion().intValue());
+        Assert.assertEquals("992", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperOptLock() {
+        Long id = 992L;
+        H2UserIntVersionExtendTO user = new H2UserIntVersionExtendTO();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2UserIntVersionExtendTO userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        H2UserIntVersionExtendTO updUser = new H2UserIntVersionExtendTO();
+        updUser.setName("999");
+
+        userService.update(updUser, new EntityWrapper<>(userDB));
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(2, userDB.getVersion().intValue());
+        Assert.assertEquals("999", userDB.getName());
+    }
+
+
+    @Test
+    public void testUpdateByEntityWrapperOptLockWithoutVersionVal() {
+        Long id = 993L;
+        H2UserIntVersionExtendTO user = new H2UserIntVersionExtendTO();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2UserIntVersionExtendTO userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        H2UserIntVersionExtendTO updUser = new H2UserIntVersionExtendTO();
+        updUser.setName("999");
+        userDB.setVersion(null);
+        userService.update(updUser, new EntityWrapper<>(userDB));
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        Assert.assertEquals("999", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperNoEntity() {
+        Long id = 998L;
+        H2UserIntVersionExtendTO user = new H2UserIntVersionExtendTO();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2UserIntVersionExtendTO userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        H2UserIntVersionExtendTO updateUser = new H2UserIntVersionExtendTO();
+        updateUser.setName("998");
+        boolean result = userService.update(updateUser, new EntityWrapper<H2UserIntVersionExtendTO>());
+        Assert.assertTrue(result);
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        EntityWrapper<H2UserIntVersionExtendTO> param = new EntityWrapper<>();
+        param.eq("name", "998");
+        List<H2UserIntVersionExtendTO> userList = userService.selectList(param);
+        Assert.assertTrue(userList.size() > 1);
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperNull() {
+        Long id = 918L;
+        H2UserIntVersionExtendTO user = new H2UserIntVersionExtendTO();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2UserIntVersionExtendTO userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        H2UserIntVersionExtendTO updateUser = new H2UserIntVersionExtendTO();
+        updateUser.setName("918");
+        updateUser.setVersion(1);
+        Assert.assertTrue(userService.update(updateUser, null));
+        EntityWrapper<H2UserIntVersionExtendTO> ew = new EntityWrapper<>();
+        int count1 = userService.selectCount(ew);
+        ew.eq("name", "918").eq("version", 1);
+        int count2 = userService.selectCount(ew);
+        List<H2UserIntVersionExtendTO> userList = userService.selectList(new EntityWrapper<H2UserIntVersionExtendTO>());
+        for (H2UserIntVersionExtendTO u : userList) {
+            System.out.println(u);
+        }
+        System.out.println("count1=" + count1 + ", count2=" + count2);
+        Assert.assertTrue(count2 > 0);
+        Assert.assertEquals(count1, count2);
+    }
+
+    @Test
+    public void testUpdateBatch() {
+        List<H2UserIntVersionExtendTO> list = userService.selectList(new EntityWrapper<H2UserIntVersionExtendTO>());
+        Map<Long, Integer> userVersionMap = new HashMap<>();
+        for (H2UserIntVersionExtendTO u : list) {
+            userVersionMap.put(u.getId(), u.getVersion());
+        }
+
+        Assert.assertTrue(userService.updateBatchById(list));
+        list = userService.selectList(new EntityWrapper<H2UserIntVersionExtendTO>());
+        for (H2UserIntVersionExtendTO user : list) {
+            Assert.assertEquals(userVersionMap.get(user.getId()) + 1, user.getVersion().intValue());
+        }
+
+    }
+
+    @Test
+    public void testUpdateInLoop() {
+        List<H2UserIntVersionExtendTO> list = userService.selectList(new EntityWrapper<H2UserIntVersionExtendTO>());
+        Map<Long, Integer> versionBefore = new HashMap<>();
+        Map<Long, String> nameExpect = new HashMap<>();
+        for (H2UserIntVersionExtendTO h2User : list) {
+            Long id = h2User.getId();
+            Integer versionVal = h2User.getVersion();
+            versionBefore.put(id, versionVal);
+            String randomName = h2User.getName() + "_" + new Random().nextInt(10);
+            nameExpect.put(id, randomName);
+            h2User.setName(randomName);
+            userService.updateById(h2User);
+        }
+
+        list = userService.selectList(new EntityWrapper<H2UserIntVersionExtendTO>());
+        for (H2UserIntVersionExtendTO u : list) {
+            Assert.assertEquals(u.getName(), nameExpect.get(u.getId()));
+            if (u.getVersion() != null)
+                Assert.assertEquals(versionBefore.get(u.getId()) + 1, u.getVersion().intValue());
+        }
+    }
+
+    @Test
+    public void testUpdateAllColumnInLoop() {
+        List<H2UserIntVersionExtendTO> list = userService.selectList(new EntityWrapper<H2UserIntVersionExtendTO>());
+        Map<Long, Integer> versionBefore = new HashMap<>();
+        Map<Long, String> nameExpect = new HashMap<>();
+        for (H2UserIntVersionExtendTO h2User : list) {
+            Long id = h2User.getId();
+            Integer versionVal = h2User.getVersion();
+            versionBefore.put(id, versionVal);
+            String randomName = h2User.getName() + "_" + new Random().nextInt(10);
+            nameExpect.put(id, randomName);
+            h2User.setName(randomName);
+            userService.updateAllColumnById(h2User);
+        }
+
+        list = userService.selectList(new EntityWrapper<H2UserIntVersionExtendTO>());
+        for (H2UserIntVersionExtendTO u : list) {
+            Assert.assertEquals(u.getName(), nameExpect.get(u.getId()));
+            Assert.assertEquals(versionBefore.get(u.getId()) + 1, u.getVersion().intValue());
+        }
+    }
+}

+ 312 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserNoOptLockTest.java

@@ -0,0 +1,312 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2User;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserService;
+
+/**
+ * <p>
+ * Mybatis Plus H2 Junit Test
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:h2/spring-test-no-opt-lock-h2.xml"})
+public class H2UserNoOptLockTest extends H2Test {
+
+    @Autowired
+    private IH2UserService userService;
+
+    @BeforeClass
+    public static void initDB() throws SQLException, IOException {
+        @SuppressWarnings("resource")
+        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:h2/spring-test-h2.xml");
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            String createTableSql = readFile("user.ddl.sql");
+            Statement stmt = conn.createStatement();
+            stmt.execute(createTableSql);
+            stmt.execute("truncate table h2user");
+            executeSql(stmt, "user.insert.sql");
+            conn.commit();
+        }
+    }
+
+    @Test
+    public void testInsert() {
+        H2User user = new H2User();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        userService.insert(user);
+        Assert.assertNotNull(user.getId());
+        user.setDesc("Caratacus");
+        userService.insertOrUpdate(user);
+        H2User userFromDB = userService.selectById(user.getId());
+        Assert.assertEquals("Caratacus", userFromDB.getDesc());
+    }
+
+    @Test
+    public void testDelete() {
+        H2User user = new H2User();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        userService.insert(user);
+        Long userId = user.getId();
+        Assert.assertNotNull(userId);
+        userService.deleteById(userId);
+        Assert.assertNull(userService.selectById(userId));
+    }
+
+    @Test
+    public void testSelectByid() {
+        Long userId = 101L;
+        Assert.assertNotNull(userService.selectById(userId));
+    }
+
+    @Test
+    public void testSelectOne() {
+        H2User user = new H2User();
+        user.setId(105L);
+        EntityWrapper<H2User> ew = new EntityWrapper<>(user);
+        H2User userFromDB = userService.selectOne(ew);
+        Assert.assertNotNull(userFromDB);
+    }
+
+    @Test
+    public void testSelectList() {
+        H2User user = new H2User();
+        EntityWrapper<H2User> ew = new EntityWrapper<>(user);
+        List<H2User> list = userService.selectList(ew);
+        Assert.assertNotNull(list);
+        Assert.assertNotEquals(0, list.size());
+    }
+
+    @Test
+    public void testSelectPage() {
+        Page<H2User> page = userService.selectPage(new Page<H2User>(1, 3));
+        Assert.assertEquals(3, page.getRecords().size());
+    }
+
+    @Test
+    public void testUpdateByIdOptLock() {
+        Long id = 991L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("991");
+        user.setAge(91);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2User userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        userDB.setName("991");
+        userService.updateById(userDB);
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        Assert.assertEquals("991", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateAllColumnByIdOptLock() {
+        Long id = 997L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("991");
+        user.setAge(91);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2User userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        userDB.setName("991");
+        userService.updateAllColumnById(userDB);
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        Assert.assertEquals("991", userDB.getName());
+
+        userDB.setName("990");
+        userService.updateById(userDB);
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        Assert.assertEquals("990", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperOptLock() {
+        Long id = 992L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2User userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        H2User updUser = new H2User();
+        updUser.setName("999");
+
+        userService.update(updUser, new EntityWrapper<>(userDB));
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        Assert.assertEquals("999", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperOptLockWithoutVersion() {
+        Long id = 993L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2User userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        H2User updUser = new H2User();
+        updUser.setName("999");
+        userDB.setVersion(null);
+        userService.update(updUser, new EntityWrapper<>(userDB));
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        Assert.assertEquals("999", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateBatch() {
+        List<H2User> list = userService.selectList(new EntityWrapper<H2User>());
+        Map<Long, Integer> userVersionMap = new HashMap<>();
+        for (H2User u : list) {
+            userVersionMap.put(u.getId(), u.getVersion());
+        }
+
+        Assert.assertTrue(userService.updateBatchById(list));
+        list = userService.selectList(new EntityWrapper<H2User>());
+        for (H2User user : list) {
+            Assert.assertEquals(userVersionMap.get(user.getId()).intValue(), user.getVersion().intValue());
+        }
+
+    }
+
+    @Test
+    public void testUpdateInLoop() {
+        List<H2User> list = userService.selectList(new EntityWrapper<H2User>());
+        Map<Long, Integer> versionBefore = new HashMap<>();
+        Map<Long, String> nameExpect = new HashMap<>();
+        for (H2User h2User : list) {
+            Long id = h2User.getId();
+            Integer versionVal = h2User.getVersion();
+            versionBefore.put(id, versionVal);
+            String randomName = h2User.getName() + "_" + new Random().nextInt(10);
+            nameExpect.put(id, randomName);
+            h2User.setName(randomName);
+            userService.updateById(h2User);
+        }
+
+        list = userService.selectList(new EntityWrapper<H2User>());
+        for (H2User u : list) {
+            Assert.assertEquals(u.getName(), nameExpect.get(u.getId()));
+            Assert.assertEquals(versionBefore.get(u.getId()).intValue(), u.getVersion().intValue());
+        }
+    }
+
+    @Test
+    public void testUpdateAllColumnInLoop() {
+        List<H2User> list = userService.selectList(new EntityWrapper<H2User>());
+        Map<Long, Integer> versionBefore = new HashMap<>();
+        Map<Long, String> nameExpect = new HashMap<>();
+        for (H2User h2User : list) {
+            Long id = h2User.getId();
+            Integer versionVal = h2User.getVersion();
+            versionBefore.put(id, versionVal);
+            String randomName = h2User.getName() + "_" + new Random().nextInt(10);
+            nameExpect.put(id, randomName);
+            h2User.setName(randomName);
+            userService.updateAllColumnById(h2User);
+        }
+
+        list = userService.selectList(new EntityWrapper<H2User>());
+        for (H2User u : list) {
+            Assert.assertEquals(u.getName(), nameExpect.get(u.getId()));
+            Assert.assertEquals(versionBefore.get(u.getId()).intValue(), u.getVersion().intValue());
+        }
+    }
+
+
+    @Test
+    public void testInsertMy() {
+        String name = "testInsertMy";
+        int version = 1;
+        int row = userService.myInsert(name, version);
+        Assert.assertEquals(1, row);
+    }
+
+    @Test
+    public void testUpdateMy() {
+        Long id = 10087L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("myUpdate");
+        user.setVersion(1);
+        userService.insert(user);
+
+        H2User dbUser = userService.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("myUpdate", dbUser.getName());
+
+        Assert.assertEquals(1, userService.myUpdate(id, "updateMy"));
+
+        dbUser = userService.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("updateMy", dbUser.getName());
+        Assert.assertEquals(1, user.getVersion().intValue());
+
+    }
+}

+ 239 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserNoVersionTest.java

@@ -0,0 +1,239 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserNoVersionMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserNoVersion;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserNoVersionService;
+
+/**
+ * <p>
+ * Mybatis Plus H2 Junit Test
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:h2/spring-test-h2.xml"})
+public class H2UserNoVersionTest extends H2Test {
+
+    @Autowired
+    IH2UserNoVersionService userService;
+
+    @Autowired
+    H2UserNoVersionMapper userMapper;
+
+    @BeforeClass
+    public static void initDB() throws SQLException, IOException {
+        @SuppressWarnings("resource")
+        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:h2/spring-test-h2.xml");
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            String createTableSql = readFile("user.ddl.sql");
+            Statement stmt = conn.createStatement();
+            stmt.execute(createTableSql);
+            stmt.execute("truncate table h2user");
+            executeSql(stmt, "user.insert.sql");
+            conn.commit();
+        }
+    }
+
+    @Test
+    public void testInsert() {
+        H2UserNoVersion user = new H2UserNoVersion();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        userService.insert(user);
+        Assert.assertNotNull(user.getId());
+        user.setDesc("Caratacus");
+        userService.insertOrUpdate(user);
+        H2UserNoVersion userFromDB = userService.selectById(user.getId());
+        Assert.assertEquals("Caratacus", userFromDB.getDesc());
+    }
+
+    @Test
+    public void testDelete() {
+        H2UserNoVersion user = new H2UserNoVersion();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        userService.insert(user);
+        Long userId = user.getId();
+        Assert.assertNotNull(userId);
+        userService.deleteById(userId);
+        Assert.assertNull(userService.selectById(userId));
+    }
+
+    @Test
+    public void testSelectByid() {
+        Long userId = 101L;
+        Assert.assertNotNull(userService.selectById(userId));
+    }
+
+    @Test
+    public void testSelectOne() {
+        H2UserNoVersion user = new H2UserNoVersion();
+        user.setId(105L);
+        EntityWrapper<H2UserNoVersion> ew = new EntityWrapper<>(user);
+        H2UserNoVersion userFromDB = userService.selectOne(ew);
+        Assert.assertNotNull(userFromDB);
+    }
+
+    @Test
+    public void testSelectList() {
+        H2UserNoVersion user = new H2UserNoVersion();
+        EntityWrapper<H2UserNoVersion> ew = new EntityWrapper<>(user);
+        List<H2UserNoVersion> list = userService.selectList(ew);
+        Assert.assertNotNull(list);
+        Assert.assertNotEquals(0, list.size());
+    }
+
+    @Test
+    public void testSelectPage() {
+        Page<H2UserNoVersion> page = userService.selectPage(new Page<H2UserNoVersion>(1, 3));
+        Assert.assertEquals(3, page.getRecords().size());
+    }
+
+    @Test
+    public void testUpdateById() {
+        Long id = 991L;
+        H2UserNoVersion user = new H2UserNoVersion();
+        user.setId(id);
+        user.setName("991");
+        user.setAge(91);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2UserNoVersion userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        userDB.setName("991");
+        userService.updateById(userDB);
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        Assert.assertEquals("991", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByEntityWrapper() {
+        Long id = 992L;
+        H2UserNoVersion user = new H2UserNoVersion();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2UserNoVersion userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        H2UserNoVersion updUser = new H2UserNoVersion();
+        updUser.setName("999");
+
+        userService.update(updUser, new EntityWrapper<>(userDB));
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        Assert.assertEquals("999", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByEntityWrapper2() {
+        Long id = 993L;
+        H2UserNoVersion user = new H2UserNoVersion();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2UserNoVersion userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        H2UserNoVersion updUser = new H2UserNoVersion();
+        updUser.setName("999");
+        userDB.setVersion(null);
+        userService.update(updUser, new EntityWrapper<>(userDB));
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        Assert.assertEquals("999", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateBatch() {
+        List<H2UserNoVersion> list = userService.selectList(new EntityWrapper<H2UserNoVersion>());
+        Map<Long, Integer> userVersionMap = new HashMap<>();
+        for (H2UserNoVersion u : list) {
+            userVersionMap.put(u.getId(), u.getVersion());
+        }
+        userService.updateBatchById(list);
+
+        list = userService.selectList(new EntityWrapper<H2UserNoVersion>());
+        for (H2UserNoVersion user : list) {
+            Assert.assertEquals(userVersionMap.get(user.getId()).intValue(), user.getVersion().intValue());
+        }
+    }
+
+
+    @Test
+    public void testInsertMy() {
+        String name = "testInsertMy";
+        int version = 1;
+        int row = userMapper.myInsertWithNameVersion(name, version);
+        Assert.assertEquals(1, row);
+    }
+
+    @Test
+    public void testUpdateMy() {
+        Long id = 10087L;
+        H2UserNoVersion user = new H2UserNoVersion();
+        user.setId(id);
+        user.setName("myUpdate");
+        user.setVersion(1);
+        userService.insert(user);
+
+        H2UserNoVersion dbUser = userService.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("myUpdate", dbUser.getName());
+
+        Assert.assertEquals(1, userMapper.myUpdateWithNameId(id, "updateMy"));
+
+        dbUser = userService.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("updateMy", dbUser.getName());
+        Assert.assertEquals(1, user.getVersion().intValue());
+
+    }
+}

+ 507 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserTest.java

@@ -0,0 +1,507 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.entity.Column;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2User;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserService;
+
+/**
+ * <p>
+ * Mybatis Plus H2 Junit Test
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:h2/spring-test-h2.xml"})
+public class H2UserTest extends H2Test {
+
+    @Autowired
+    private IH2UserService userService;
+
+    @Autowired
+    H2UserMapper userMapper;
+
+    @BeforeClass
+    public static void initDB() throws SQLException, IOException {
+        @SuppressWarnings("resource")
+        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:h2/spring-test-h2.xml");
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            String createTableSql = readFile("user.ddl.sql");
+            Statement stmt = conn.createStatement();
+            stmt.execute(createTableSql);
+            stmt.execute("truncate table h2user");
+            executeSql(stmt, "user.insert.sql");
+            conn.commit();
+        }
+    }
+
+    @Test
+    public void testInsert() {
+        H2User user = new H2User();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        userService.insert(user);
+        Assert.assertNotNull(user.getId());
+        user.setDesc("Caratacus");
+        userService.insertOrUpdate(user);
+        H2User userFromDB = userService.selectById(user.getId());
+        Assert.assertEquals("Caratacus", userFromDB.getDesc());
+    }
+
+    @Test
+    public void testInsertBatch() {
+        userService.insert(new H2User("sanmao", 1));
+        List<H2User> h2Users = new ArrayList<>();
+        for (int i = 0; i < 10; i++) {
+            H2User user = new H2User();
+            user.setAge(1);
+            user.setPrice(new BigDecimal("6" + i));
+            user.setDesc("testBatch" + i);
+            h2Users.add(user);
+        }
+        Assert.assertTrue(userService.insertBatch(h2Users));
+    }
+
+    @Test
+    public void testDelete() {
+        H2User user = new H2User();
+        user.setAge(1);
+        user.setPrice(new BigDecimal("9.99"));
+        userService.insert(user);
+        Long userId = user.getId();
+        Assert.assertNotNull(userId);
+        userService.deleteById(userId);
+        Assert.assertNull(userService.selectById(userId));
+    }
+
+    @Test
+    public void testSelectByid() {
+        Long userId = 101L;
+        Assert.assertNotNull(userService.selectById(userId));
+    }
+
+    @Test
+    public void testSelectOne() {
+        H2User user = new H2User();
+        user.setId(105L);
+        EntityWrapper<H2User> ew = new EntityWrapper<>(user);
+        H2User userFromDB = userService.selectOne(ew);
+        Assert.assertNotNull(userFromDB);
+    }
+
+    @Test
+    public void testSelectList() {
+        H2User user = new H2User();
+        EntityWrapper<H2User> ew = new EntityWrapper<>(user);
+        List<H2User> list = userService.selectList(ew);
+        Assert.assertNotNull(list);
+        Assert.assertNotEquals(0, list.size());
+    }
+
+    @Test
+    public void testSelectPage() {
+        Page<H2User> page = userService.selectPage(new Page<H2User>(1, 3));
+        Assert.assertEquals(3, page.getRecords().size());
+    }
+
+    @Test
+    public void testUpdateByIdOptLock() {
+        Long id = 991L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("991");
+        user.setAge(91);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2User userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        userDB.setName("991");
+        userService.updateById(userDB);
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(2, userDB.getVersion().intValue());
+        Assert.assertEquals("991", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateAllColumnByIdOptLock() {
+        Long id = 997L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("991");
+        user.setAge(91);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2User userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        userDB.setName("991");
+        userService.updateAllColumnById(userDB);
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(2, userDB.getVersion().intValue());
+        Assert.assertEquals("991", userDB.getName());
+
+        userDB.setName("990");
+        userService.updateById(userDB);
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(3, userDB.getVersion().intValue());
+        Assert.assertEquals("990", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperOptLock() {
+        Long id = 1992L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2User userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        H2User updUser = new H2User();
+        updUser.setName("999");
+
+        userService.update(updUser, new EntityWrapper<>(userDB));
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(2, userDB.getVersion().intValue());
+        Assert.assertEquals("999", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperOptLockWithoutVersionVal() {
+        Long id = 993L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2User userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+
+        H2User updUser = new H2User();
+        updUser.setName("999");
+        userDB.setVersion(null);
+        userService.update(updUser, new EntityWrapper<>(userDB));
+
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        Assert.assertEquals("999", userDB.getName());
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperNoEntity() {
+        Long id = 998L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2User userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        H2User updateUser = new H2User();
+        updateUser.setName("998");
+        boolean result = userService.update(updateUser, new EntityWrapper<H2User>());
+        Assert.assertTrue(result);
+        userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        EntityWrapper<H2User> param = new EntityWrapper<>();
+        param.eq("name", "998");
+        List<H2User> userList = userService.selectList(param);
+        Assert.assertTrue(userList.size() > 1);
+    }
+
+    @Test
+    public void testUpdateByEntityWrapperNull() {
+        Long id = 918L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("992");
+        user.setAge(92);
+        user.setPrice(BigDecimal.TEN);
+        user.setDesc("asdf");
+        user.setTestType(1);
+        user.setVersion(1);
+        userService.insertAllColumn(user);
+
+        H2User userDB = userService.selectById(id);
+        Assert.assertEquals(1, userDB.getVersion().intValue());
+        H2User updateUser = new H2User();
+        updateUser.setName("918");
+        updateUser.setVersion(1);
+        Assert.assertTrue(userService.update(updateUser, null));
+        EntityWrapper<H2User> ew = new EntityWrapper<>();
+        int count1 = userService.selectCount(ew);
+        ew.eq("name", "918").eq("version", 1);
+        int count2 = userService.selectCount(ew);
+        List<H2User> userList = userService.selectList(new EntityWrapper<H2User>());
+        for (H2User u : userList) {
+            System.out.println(u);
+        }
+        System.out.println("count1=" + count1 + ", count2=" + count2);
+        Assert.assertTrue(count2 > 0);
+        Assert.assertEquals(count1, count2);
+    }
+
+    @Test
+    public void testUpdateBatch() {
+        List<H2User> list = userService.selectList(new EntityWrapper<H2User>());
+        Map<Long, Integer> userVersionMap = new HashMap<>();
+        for (H2User u : list) {
+            userVersionMap.put(u.getId(), u.getVersion());
+        }
+
+        Assert.assertTrue(userService.updateBatchById(list));
+        list = userService.selectList(new EntityWrapper<H2User>());
+        for (H2User user : list) {
+            Assert.assertEquals(userVersionMap.get(user.getId()) + 1, user.getVersion().intValue());
+        }
+
+    }
+
+    @Test
+    public void testUpdateInLoop() {
+        List<H2User> list = userService.selectList(new EntityWrapper<H2User>());
+        Map<Long, Integer> versionBefore = new HashMap<>();
+        Map<Long, String> nameExpect = new HashMap<>();
+        for (H2User h2User : list) {
+            Long id = h2User.getId();
+            Integer versionVal = h2User.getVersion();
+            versionBefore.put(id, versionVal);
+            String randomName = h2User.getName() + "_" + new Random().nextInt(10);
+            nameExpect.put(id, randomName);
+            h2User.setName(randomName);
+            userService.updateById(h2User);
+        }
+
+        list = userService.selectList(new EntityWrapper<H2User>());
+        for (H2User u : list) {
+            Assert.assertEquals(u.getName(), nameExpect.get(u.getId()));
+            if (u.getVersion() != null)
+                Assert.assertEquals(versionBefore.get(u.getId()) + 1, u.getVersion().intValue());
+        }
+    }
+
+    @Test
+    public void testUpdateAllColumnInLoop() {
+        List<H2User> list = userService.selectList(new EntityWrapper<H2User>());
+        Map<Long, Integer> versionBefore = new HashMap<>();
+        Map<Long, String> nameExpect = new HashMap<>();
+        for (H2User h2User : list) {
+            Long id = h2User.getId();
+            Integer versionVal = h2User.getVersion();
+            versionBefore.put(id, versionVal);
+            String randomName = h2User.getName() + "_" + new Random().nextInt(10);
+            nameExpect.put(id, randomName);
+            h2User.setName(randomName);
+            userService.updateAllColumnById(h2User);
+        }
+
+        list = userService.selectList(new EntityWrapper<H2User>());
+        for (H2User u : list) {
+            Assert.assertEquals(u.getName(), nameExpect.get(u.getId()));
+            Assert.assertEquals(versionBefore.get(u.getId()) + 1, u.getVersion().intValue());
+        }
+    }
+
+    @Test
+    public void testInsertMy() {
+        String name = "自定义insert";
+        int version = 1;
+        int row = userService.myInsert(name, version);
+        Assert.assertEquals(1, row);
+    }
+
+    @Test
+    public void testInsertObjectWithParam() {
+        String name = "自定义insert带Param注解";
+        int version = 1;
+        int row = userService.myInsertWithParam(name, version);
+        Assert.assertEquals(1, row);
+    }
+
+    @Test
+    public void testInsertObjectWithoutParam() {
+        String name = "自定义insert带Param注解";
+        int version = 1;
+        int row = userService.myInsertWithoutParam(name, version);
+        Assert.assertEquals(1, row);
+    }
+
+    @Test
+    public void testUpdateMy() {
+        Long id = 10087L;
+        H2User user = new H2User();
+        user.setId(id);
+        user.setName("myUpdate");
+        user.setVersion(1);
+        userService.insert(user);
+
+        H2User dbUser = userService.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("myUpdate", dbUser.getName());
+
+        Assert.assertEquals(1, userService.myUpdate(id, "updateMy"));
+
+        dbUser = userService.selectById(id);
+        Assert.assertNotNull(dbUser);
+        Assert.assertEquals("updateMy", dbUser.getName());
+        Assert.assertEquals(1, user.getVersion().intValue());
+    }
+
+
+    @Test
+    public void testCondition() {
+        Page<H2User> page = new Page<>(1, 3);
+        Map<String, Object> condition = new HashMap<>();
+        condition.put("test_type", 1);
+        page.setCondition(condition);
+        Page<H2User> pageResult = userService.selectPage(page);
+        for (H2User u : pageResult.getRecords()) {
+            System.out.println(u);
+        }
+        System.out.println(pageResult.getTotal());
+
+    }
+
+
+    @Test
+    public void testEntityWrapperSelectSql() {
+        EntityWrapper<H2User> ew = new EntityWrapper<>();
+        ew.setSqlSelect("test_id as id, name, age");
+        List<H2User> list = userService.selectList(ew);
+        for (H2User u : list) {
+            Assert.assertNotNull(u.getId());
+            Assert.assertNotNull(u.getName());
+            Assert.assertNull(u.getPrice());
+        }
+
+    }
+
+    @Test
+    public void testQueryWithParamInSelectStatement() {
+        Map<String, Object> param = new HashMap<>();
+        String nameParam = "selectStmtParam";
+        param.put("nameParam", nameParam);
+        param.put("ageFrom", 1);
+        param.put("ageTo", 100);
+        List<H2User> list = userService.queryWithParamInSelectStatememt(param);
+        Assert.assertNotNull(list);
+        for (H2User u : list) {
+            Assert.assertEquals(nameParam, u.getName());
+            Assert.assertNotNull(u.getId());
+        }
+    }
+
+    @Test
+    public void testQueryWithParamInSelectStatement4Page() {
+        Map<String, Object> param = new HashMap<>();
+        String nameParam = "selectStmtParam";
+        param.put("nameParam", nameParam);
+        param.put("ageFrom", 1);
+        param.put("ageTo", 100);
+        Page<H2User> page = userService.queryWithParamInSelectStatememt4Page(param, new Page<H2User>(0, 10));
+        Assert.assertNotNull(page.getRecords());
+        for (H2User u : page.getRecords()) {
+            Assert.assertEquals(nameParam, u.getName());
+            Assert.assertNotNull(u.getId());
+        }
+        Assert.assertNotEquals(0, page.getTotal());
+    }
+
+    @Test
+    public void testSelectCountWithParamInSelectItems() {
+        Map<String, Object> param = new HashMap<>();
+        String nameParam = "selectStmtParam";
+        param.put("nameParam", nameParam);
+        param.put("ageFrom", 1);
+        param.put("ageTo", 100);
+        int count = userService.selectCountWithParamInSelectItems(param);
+        Assert.assertNotEquals(0, count);
+    }
+
+    @Test
+    public void testPageWithDollarParamInSelectItems() {
+        Map<String, Object> param = new HashMap<>();
+        String nameParam = "selectStmtParam";
+        param.put("nameParam", nameParam);
+        param.put("ageFrom", 1);
+        param.put("ageTo", 100);
+        Page<H2User> page = new Page<H2User>(0, 10);
+        userMapper.selectUserWithDollarParamInSelectStatememt4Page(param, page);
+        Assert.assertNotEquals(0, page.getTotal());
+
+    }
+
+    @Test
+    public void testDistinctColumn() {
+        EntityWrapper<H2User> ew = new EntityWrapper<>();
+        ew.setSqlSelect(Column.create().column("distinct test_type"));//setMapUnderscoreToCamelCase(true)
+        List<H2User> list = userService.selectList(ew);
+        for (H2User u : list) {
+            System.out.println("getTestType=" + u.getTestType());
+            Assert.assertNotNull(u.getTestType());
+        }
+        ew.setSqlSelect("distinct test_type as testType");
+        for (H2User u : userService.selectList(ew)) {
+            System.out.println("testType=" + u.getTestType());
+            Assert.assertNotNull(u.getTestType());
+        }
+    }
+
+}

+ 58 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2uuidTest.java

@@ -0,0 +1,58 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2uuidMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2uuid;
+
+/**
+ * <p>
+ * Mybatis Plus H2 Junit Test
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:h2/spring-test-h2.xml"})
+public class H2uuidTest extends H2Test {
+
+    @Autowired
+    private H2uuidMapper uuidMapper;
+
+    @BeforeClass
+    public static void initDB() throws SQLException, IOException {
+        @SuppressWarnings("resource")
+        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:h2/spring-test-h2.xml");
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            Statement stmt = conn.createStatement();
+            stmt.execute(readFile("uuid.sql"));
+            stmt.execute("truncate table h2uuid");
+            conn.commit();
+        }
+    }
+
+    @Test
+    public void testUuid() {
+        H2uuid h2uuid = new H2uuid("3");
+        Assert.assertEquals(1, uuidMapper.insert(h2uuid).intValue());
+        Assert.assertTrue(h2uuid.getId().length() == 32);
+    }
+
+}

+ 41 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/DBConfig.java

@@ -0,0 +1,41 @@
+package com.baomidou.mybatisplus.test.h2.config;
+
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+import org.h2.Driver;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.jdbc.datasource.SimpleDriverDataSource;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+/**
+ * <p>
+ * H2 Memory Database config
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@Configuration
+@EnableTransactionManagement
+public class DBConfig {
+
+    @Bean
+    public DataSource dataSource() throws SQLException {
+        SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
+        dataSource.setDriver(new Driver());
+        dataSource.setUrl("jdbc:h2:mem:test;MODE=mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
+        dataSource.setUsername("sa");
+        dataSource.setPassword("");
+        return dataSource;
+    }
+
+    @Bean
+    public DataSourceTransactionManager transactionManager(DataSource ds) {
+        return new DataSourceTransactionManager(ds);
+    }
+
+}

+ 64 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisConfigMetaObjOptLockConfig.java

@@ -0,0 +1,64 @@
+package com.baomidou.mybatisplus.test.h2.config;
+
+import javax.sql.DataSource;
+
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.type.JdbcType;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ResourceLoader;
+
+import com.baomidou.mybatisplus.MybatisConfiguration;
+import com.baomidou.mybatisplus.MybatisXMLLanguageDriver;
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.mapper.LogicSqlInjector;
+import com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor;
+import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.plugins.PerformanceInterceptor;
+import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean;
+import com.baomidou.mybatisplus.test.h2.H2MetaObjectHandler;
+
+/**
+ * <p>
+ * MetaObj
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/29
+ */
+@Configuration
+@MapperScan("com.baomidou.mybatisplus.test.h2.entity.mapper")
+public class MybatisConfigMetaObjOptLockConfig {
+
+    @Bean("mybatisSqlSession")
+    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, ResourceLoader resourceLoader, GlobalConfiguration globalConfiguration) throws Exception {
+        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
+        sqlSessionFactory.setDataSource(dataSource);
+//        sqlSessionFactory.setConfigLocation(resourceLoader.getResource("classpath:mybatis-config.xml"));
+        sqlSessionFactory.setTypeAliasesPackage("com.baomidou.mybatisplus.test.h2.entity.persistent");
+        MybatisConfiguration configuration = new MybatisConfiguration();
+        configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
+        configuration.setJdbcTypeForNull(JdbcType.NULL);
+        sqlSessionFactory.setConfiguration(configuration);
+        PaginationInterceptor pagination = new PaginationInterceptor();
+        sqlSessionFactory.setPlugins(new Interceptor[]{
+                pagination,
+                new PerformanceInterceptor(),
+                new OptimisticLockerInterceptor()
+        });
+        sqlSessionFactory.setGlobalConfig(globalConfiguration);
+        return sqlSessionFactory.getObject();
+    }
+
+    @Bean
+    public GlobalConfiguration globalConfiguration() {
+        GlobalConfiguration conf = new GlobalConfiguration(new LogicSqlInjector());
+        conf.setLogicDeleteValue("-1");
+        conf.setLogicNotDeleteValue("1");
+        conf.setIdType(2);
+        conf.setMetaObjectHandler(new H2MetaObjectHandler());
+        return conf;
+    }
+}

+ 66 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusConfig.java

@@ -0,0 +1,66 @@
+package com.baomidou.mybatisplus.test.h2.config;
+
+import javax.sql.DataSource;
+
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.type.JdbcType;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ResourceLoader;
+
+import com.baomidou.mybatisplus.MybatisConfiguration;
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.mapper.LogicSqlInjector;
+import com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor;
+import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.plugins.PerformanceInterceptor;
+import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean;
+import com.baomidou.mybatisplus.test.h2.H2MetaObjectHandler;
+
+/**
+ * <p>
+ * Mybatis Plus Config
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@Configuration
+@MapperScan("com.baomidou.mybatisplus.test.h2.entity.mapper")
+public class MybatisPlusConfig {
+
+    @Bean("mybatisSqlSession")
+    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, ResourceLoader resourceLoader, GlobalConfiguration globalConfiguration) throws Exception {
+        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
+        sqlSessionFactory.setDataSource(dataSource);
+//        sqlSessionFactory.setConfigLocation(resourceLoader.getResource("classpath:mybatis-config.xml"));
+        sqlSessionFactory.setTypeAliasesPackage("com.baomidou.mybatisplus.test.h2.entity.persistent");
+        MybatisConfiguration configuration = new MybatisConfiguration();
+//        configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
+//        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
+        configuration.setJdbcTypeForNull(JdbcType.NULL);
+        configuration.setMapUnderscoreToCamelCase(true);
+        sqlSessionFactory.setConfiguration(configuration);
+        PaginationInterceptor pagination = new PaginationInterceptor();
+        OptimisticLockerInterceptor optLock = new OptimisticLockerInterceptor();
+        sqlSessionFactory.setPlugins(new Interceptor[]{
+                pagination,
+                optLock,
+                new PerformanceInterceptor()
+        });
+        globalConfiguration.setMetaObjectHandler(new H2MetaObjectHandler());
+        sqlSessionFactory.setGlobalConfig(globalConfiguration);
+        return sqlSessionFactory.getObject();
+    }
+
+    @Bean
+    public GlobalConfiguration globalConfiguration() {
+        GlobalConfiguration conf = new GlobalConfiguration(new LogicSqlInjector());
+        conf.setLogicDeleteValue("-1");
+        conf.setLogicNotDeleteValue("1");
+        conf.setIdType(2);
+        return conf;
+    }
+}

+ 63 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusLoginDeleteConfig.java

@@ -0,0 +1,63 @@
+package com.baomidou.mybatisplus.test.h2.config;
+
+import javax.sql.DataSource;
+
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.type.JdbcType;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ResourceLoader;
+
+import com.baomidou.mybatisplus.MybatisConfiguration;
+import com.baomidou.mybatisplus.MybatisXMLLanguageDriver;
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.mapper.LogicSqlInjector;
+import com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor;
+import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.plugins.PerformanceInterceptor;
+import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean;
+
+/**
+ * <p>
+ * 逻辑删除boot方式注入
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/15
+ */
+@Configuration
+@MapperScan("com.baomidou.mybatisplus.test.h2.entity.mapper")
+public class MybatisPlusLoginDeleteConfig {
+
+    @Bean("mybatisSqlSession")
+    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, ResourceLoader resourceLoader, GlobalConfiguration globalConfiguration) throws Exception {
+        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
+        sqlSessionFactory.setDataSource(dataSource);
+//        sqlSessionFactory.setConfigLocation(resourceLoader.getResource("classpath:mybatis-config.xml"));
+        sqlSessionFactory.setTypeAliasesPackage("com.baomidou.mybatisplus.test.h2.entity.persistent");
+        MybatisConfiguration configuration = new MybatisConfiguration();
+        configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
+        configuration.setJdbcTypeForNull(JdbcType.NULL);
+        sqlSessionFactory.setConfiguration(configuration);
+        PaginationInterceptor pagination = new PaginationInterceptor();
+        OptimisticLockerInterceptor optLock = new OptimisticLockerInterceptor();
+        sqlSessionFactory.setPlugins(new Interceptor[]{
+                pagination,
+                optLock,
+                new PerformanceInterceptor()
+        });
+        sqlSessionFactory.setGlobalConfig(globalConfiguration);
+        return sqlSessionFactory.getObject();
+    }
+
+    @Bean
+    public GlobalConfiguration globalConfiguration() {
+        GlobalConfiguration conf = new GlobalConfiguration(new LogicSqlInjector());
+        conf.setLogicDeleteValue("-1");
+        conf.setLogicNotDeleteValue("1");
+        conf.setIdType(2);
+        return conf;
+    }
+}

+ 59 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusMetaObjConfig.java

@@ -0,0 +1,59 @@
+package com.baomidou.mybatisplus.test.h2.config;
+
+import javax.sql.DataSource;
+
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.type.JdbcType;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ResourceLoader;
+
+import com.baomidou.mybatisplus.MybatisConfiguration;
+import com.baomidou.mybatisplus.MybatisXMLLanguageDriver;
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.plugins.PerformanceInterceptor;
+import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean;
+import com.baomidou.mybatisplus.test.h2.H2MetaObjectHandler;
+
+/**
+ * <p>
+ * Mybatis Plus Config without OptimisLock
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@Configuration
+@MapperScan("com.baomidou.mybatisplus.test.h2.entity.mapper")
+public class MybatisPlusMetaObjConfig {
+
+    @Bean("mybatisSqlSession")
+    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, ResourceLoader resourceLoader, GlobalConfiguration globalConfiguration) throws Exception {
+        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
+        sqlSessionFactory.setDataSource(dataSource);
+//        sqlSessionFactory.setConfigLocation(resourceLoader.getResource("classpath:mybatis-config.xml"));
+        sqlSessionFactory.setTypeAliasesPackage("com.baomidou.mybatisplus.test.h2.entity.persistent");
+        MybatisConfiguration configuration = new MybatisConfiguration();
+        configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
+        configuration.setJdbcTypeForNull(JdbcType.NULL);
+        sqlSessionFactory.setConfiguration(configuration);
+        PaginationInterceptor pagination = new PaginationInterceptor();
+        sqlSessionFactory.setPlugins(new Interceptor[]{
+                pagination,
+                new PerformanceInterceptor()
+        });
+        sqlSessionFactory.setGlobalConfig(globalConfiguration);
+        return sqlSessionFactory.getObject();
+    }
+
+    @Bean
+    public GlobalConfiguration globalConfiguration() {
+        GlobalConfiguration globalConfiguration = new GlobalConfiguration();
+        globalConfiguration.setIdType(2);
+        globalConfiguration.setMetaObjectHandler(new H2MetaObjectHandler());
+        return globalConfiguration;
+    }
+}

+ 55 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusNoOptLockConfig.java

@@ -0,0 +1,55 @@
+package com.baomidou.mybatisplus.test.h2.config;
+
+import javax.sql.DataSource;
+
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.type.JdbcType;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ResourceLoader;
+
+import com.baomidou.mybatisplus.MybatisConfiguration;
+import com.baomidou.mybatisplus.MybatisXMLLanguageDriver;
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean;
+
+/**
+ * <p>
+ * Mybatis Plus Config without OptimisLock
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@Configuration
+@MapperScan("com.baomidou.mybatisplus.test.h2.entity.mapper")
+public class MybatisPlusNoOptLockConfig {
+
+    @Bean("mybatisSqlSession")
+    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, ResourceLoader resourceLoader, GlobalConfiguration globalConfiguration) throws Exception {
+        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
+        sqlSessionFactory.setDataSource(dataSource);
+//        sqlSessionFactory.setConfigLocation(resourceLoader.getResource("classpath:mybatis-config.xml"));
+        sqlSessionFactory.setTypeAliasesPackage("com.baomidou.mybatisplus.test.h2.entity.persistent");
+        MybatisConfiguration configuration = new MybatisConfiguration();
+        configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
+        configuration.setJdbcTypeForNull(JdbcType.NULL);
+        sqlSessionFactory.setConfiguration(configuration);
+        PaginationInterceptor pagination = new PaginationInterceptor();
+        sqlSessionFactory.setPlugins(new Interceptor[]{
+                pagination,
+        });
+        sqlSessionFactory.setGlobalConfig(globalConfiguration);
+        return sqlSessionFactory.getObject();
+    }
+
+    @Bean
+    public GlobalConfiguration globalConfiguration() {
+        GlobalConfiguration globalConfiguration = new GlobalConfiguration();
+        globalConfiguration.setIdType(2);
+        return globalConfiguration;
+    }
+}

+ 64 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusSequenceConfig.java

@@ -0,0 +1,64 @@
+package com.baomidou.mybatisplus.test.h2.config;
+
+import javax.sql.DataSource;
+
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.type.JdbcType;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ResourceLoader;
+
+import com.baomidou.mybatisplus.MybatisConfiguration;
+import com.baomidou.mybatisplus.MybatisXMLLanguageDriver;
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.incrementer.H2KeyGenerator;
+import com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor;
+import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.plugins.PerformanceInterceptor;
+import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean;
+
+/**
+ * <p>
+ * H2 Sequence
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@Configuration
+@MapperScan("com.baomidou.mybatisplus.test.h2.entity.mapper")
+public class MybatisPlusSequenceConfig {
+
+    @Bean("mybatisSqlSession")
+    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, ResourceLoader resourceLoader, GlobalConfiguration globalConfiguration) throws Exception {
+        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
+        sqlSessionFactory.setDataSource(dataSource);
+//        sqlSessionFactory.setConfigLocation(resourceLoader.getResource("classpath:mybatis-config.xml"));
+        sqlSessionFactory.setTypeAliasesPackage("com.baomidou.mybatisplus.test.h2.entity.persistent");
+        MybatisConfiguration configuration = new MybatisConfiguration();
+        configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
+        configuration.setJdbcTypeForNull(JdbcType.NULL);
+        configuration.setMapUnderscoreToCamelCase(true);
+        sqlSessionFactory.setConfiguration(configuration);
+        PaginationInterceptor pagination = new PaginationInterceptor();
+        sqlSessionFactory.setPlugins(new Interceptor[]{
+                pagination,
+                new OptimisticLockerInterceptor(),
+                new PerformanceInterceptor()
+        });
+        sqlSessionFactory.setGlobalConfig(globalConfiguration);
+        return sqlSessionFactory.getObject();
+    }
+
+    @Bean
+    public GlobalConfiguration globalConfiguration() {
+        GlobalConfiguration conf = new GlobalConfiguration();
+        conf.setIdType(2);
+//        conf.setDbType("h2");
+        conf.setKeyGenerator(new H2KeyGenerator());
+//        conf.setDbColumnUnderline(true);
+        return conf;
+    }
+}

+ 20 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/ServiceConfig.java

@@ -0,0 +1,20 @@
+package com.baomidou.mybatisplus.test.h2.config;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/15
+ */
+@Configuration
+@Import(value = {DBConfig.class, MybatisPlusConfig.class})
+@ComponentScan("com.baomidou.mybatisplus.test.h2.service")
+public class ServiceConfig {
+
+
+}

+ 20 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/config/ServiceSequenceConfig.java

@@ -0,0 +1,20 @@
+package com.baomidou.mybatisplus.test.h2.config;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+/**
+ * <p>
+ * H2 Sequence test config
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@Configuration
+@Import(value = {DBConfig.class, MybatisPlusSequenceConfig.class})
+@ComponentScan("com.baomidou.mybatisplus.test.h2.service")
+public class ServiceSequenceConfig {
+
+}

+ 44 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/SuperEntity.java

@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.h2.entity;
+
+import java.io.Serializable;
+
+import com.baomidou.mybatisplus.annotations.TableId;
+
+/**
+ * <p>
+ * 测试父类情况
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-06-26
+ */
+public class SuperEntity implements Serializable {
+
+    /* 主键ID 注解,value 字段名,type 用户输入ID */
+    @TableId(value = "test_id")
+    private Long id;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+}
+

+ 14 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/SuperMapper.java

@@ -0,0 +1,14 @@
+package com.baomidou.mybatisplus.test.h2.entity;
+
+/**
+ * <p>
+ * 自定义父类 SuperMapper
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-06-26
+ */
+public interface SuperMapper<T> extends com.baomidou.mybatisplus.mapper.BaseMapper<T> {
+
+    // 这里可以写 mapper 层公共方法、 注意!! 不要让在 mapper 目录让 mp 扫描到!!
+}

+ 29 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserDateVersionMapper.java

@@ -0,0 +1,29 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserDateVersion;
+
+/**
+ * <p>
+ * H2User without version column
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+public interface H2UserDateVersionMapper extends BaseMapper<H2UserDateVersion> {
+
+    @Insert(
+            "insert into h2user(name,version) values(#{name},#{version})"
+    )
+    int myInsertWithNameVersion(@Param("name") String name, @Param("version") int version);
+
+    @Update(
+            "update h2user set name=#{name} where test_id=#{id}"
+    )
+    int myUpdateWithNameId(@Param("id") Long id, @Param("name") String name);
+}

+ 28 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserExtendsMapper.java

@@ -0,0 +1,28 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserIntVersionExtendTO;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+public interface H2UserExtendsMapper extends BaseMapper<H2UserIntVersionExtendTO> {
+
+    @Insert(
+            "insert into h2user(name,version) values(#{name},#{version})"
+    )
+    int myInsertWithNameVersion(@Param("name") String name, @Param("version") int version);
+
+    @Update(
+            "update h2user set name=#{name} where test_id=#{id}"
+    )
+    int myUpdateWithNameId(@Param("id") Long id, @Param("name") String name);
+}

+ 35 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserLogicDeleteMapper.java

@@ -0,0 +1,35 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserLogicDelete;
+
+/**
+ * <p>
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/15
+ */
+public interface H2UserLogicDeleteMapper extends BaseMapper<H2UserLogicDelete> {
+
+    @Insert(
+            "insert into h2user(name,version) values(#{name},#{version})"
+    )
+    int myInsertWithNameVersion(@Param("name") String name, @Param("version") int version);
+
+    @Update(
+            "update h2user set name=#{name} where test_id=#{id}"
+    )
+    int myUpdateWithNameId(@Param("id") Long id, @Param("name") String name);
+
+    @Select(
+            "select test_id as id, name, age, version, test_type as testType from h2user where test_id=#{id}"
+    )
+    H2UserLogicDelete selectByIdMy(@Param("id") Long id);
+}

+ 83 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserMapper.java

@@ -0,0 +1,83 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.h2.entity.SuperMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2Addr;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2User;
+
+/**
+ * <p>
+ * 这里继承自定义父类 SuperMapper
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+public interface H2UserMapper extends SuperMapper<H2User> {
+
+    @Select(
+            "select a.addr_id as addrId, a.addr_name as addrName from h2address a" +
+                    " join h2user u on u.test_id=a.test_id and u.test_id=#{userId}"
+    )
+    List<H2Addr> getAddrListByUserId(@Param("userId") Long userId);
+
+    @Select(
+            "select a.addr_id as addrId, a.addr_name as addrName from h2address a" +
+                    " join h2user u on u.test_id=a.test_id and u.test_id=#{userId}"
+    )
+    List<H2Addr> getAddrListByUserIdPage(@Param("userId") Long userId, Page<H2Addr> page);
+
+    @Insert(
+            "insert into h2user(name,version) values(#{name},#{version})"
+    )
+    int myInsertWithNameVersion(@Param("name") String name, @Param("version") int version);
+
+    @Update(
+            "update h2user set name=#{name} where test_id=#{id}"
+    )
+    int myUpdateWithNameId(@Param("id") Long id, @Param("name") String name);
+
+
+    @Insert(
+            "insert into h2user(name,version) values( #{user1.name}, #{user1.version})"
+    )
+    int myInsertWithParam(@Param("user1") H2User user1);
+
+    @Insert(
+            "insert into h2user(name,version) values( #{name}, #{version})"
+    )
+    int myInsertWithoutParam(H2User user1);
+
+
+    @Select(" select test_id as id, power(#{ageFrom},2), 'abc?zhazha', CAST(#{nameParam} AS VARCHAR) as name " +
+            " from h2user " +
+            " where age>#{ageFrom} and age<#{ageTo} ")
+    List<H2User> selectUserWithParamInSelectStatememt(Map<String,Object> param);
+
+    @Select(" select test_id as id, power(#{ageFrom},2), 'abc?zhazha', CAST(#{nameParam} AS VARCHAR) as name " +
+            " from h2user " +
+            " where age>#{ageFrom} and age<#{ageTo} ")
+    List<H2User> selectUserWithParamInSelectStatememt4Page(Map<String,Object> param, Page<H2User> page);
+
+    @Select(" select test_id as id, power(${ageFrom},2), '${nameParam}' as name " +
+            " from h2user " +
+            " where age>#{ageFrom} and age<#{ageTo} ")
+    List<H2User> selectUserWithDollarParamInSelectStatememt4Page(Map<String,Object> param, Page<H2User> page);
+
+
+
+    @Select("select count(1) from (" +
+            "select test_id as id, CAST(#{nameParam} AS VARCHAR) as name" +
+            " from h2user " +
+            " where age>#{ageFrom} and age<#{ageTo} " +
+            ") a")
+    int selectCountWithParamInSelectItems(Map<String,Object> param);
+}

+ 28 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserMetaobjMapper.java

@@ -0,0 +1,28 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserMetaObj;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+public interface H2UserMetaobjMapper extends BaseMapper<H2UserMetaObj> {
+
+    @Insert(
+            "insert into h2user(name,version) values(#{name},#{version})"
+    )
+    int myInsertWithNameVersion(@Param("name") String name, @Param("version") int version);
+
+    @Update(
+            "update h2user set name=#{name} where test_id=#{id}"
+    )
+    int myUpdateWithNameId(@Param("id") Long id, @Param("name") String name);
+}

+ 29 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserNoVersionMapper.java

@@ -0,0 +1,29 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserNoVersion;
+
+/**
+ * <p>
+ * H2User without version column
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+public interface H2UserNoVersionMapper extends BaseMapper<H2UserNoVersion> {
+
+    @Insert(
+            "insert into h2user(name,version) values(#{name},#{version})"
+    )
+    int myInsertWithNameVersion(@Param("name") String name, @Param("version") int version);
+
+    @Update(
+            "update h2user set name=#{name} where test_id=#{id}"
+    )
+    int myUpdateWithNameId(@Param("id") Long id, @Param("name") String name);
+}

+ 28 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserSequenceExtendsMapper.java

@@ -0,0 +1,28 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserSequenceExtendTO;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+public interface H2UserSequenceExtendsMapper extends BaseMapper<H2UserSequenceExtendTO> {
+
+    @Insert(
+            "insert into h2user(name,version) values(#{name},#{version})"
+    )
+    int myInsertWithNameVersion(@Param("name") String name, @Param("version") int version);
+
+    @Update(
+            "update h2user set name=#{name} where test_id=#{id}"
+    )
+    int myUpdateWithNameId(@Param("id") Long id, @Param("name") String name);
+}

+ 28 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserSequenceMapper.java

@@ -0,0 +1,28 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserSequence;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+public interface H2UserSequenceMapper extends BaseMapper<H2UserSequence> {
+
+    @Insert(
+            "insert into h2user(name,version) values(#{name},#{version})"
+    )
+    int myInsertWithNameVersion(@Param("name") String name, @Param("version") int version);
+
+    @Update(
+            "update h2user set name=#{name} where test_id=#{id}"
+    )
+    int myUpdateWithNameId(@Param("id") Long id, @Param("name") String name);
+}

+ 58 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserVersionAndLogicDeleteMapper.java

@@ -0,0 +1,58 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2Addr;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserVersionAndLogicDeleteEntity;
+
+/**
+ * <p>
+ * 带version和逻辑删除
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/29
+ */
+public interface H2UserVersionAndLogicDeleteMapper extends BaseMapper<H2UserVersionAndLogicDeleteEntity> {
+
+
+    @Select(
+            "select a.addr_id as addrId, a.addr_name as addrName from h2address a" +
+                    " join h2user u on u.test_id=a.test_id and u.test_id=#{userId}"
+    )
+    List<H2Addr> getAddrListByUserId(@Param("userId") Long userId);
+
+    @Select(
+            "select a.addr_id as addrId, a.addr_name as addrName from h2address a" +
+                    " join h2user u on u.test_id=a.test_id and u.test_id=#{userId}"
+    )
+    List<H2Addr> getAddrListByUserIdPage(@Param("userId") Long userId, Page<H2Addr> page);
+
+    @Insert(
+            "insert into h2user(name,version) values(#{name},#{version})"
+    )
+    int myInsertWithNameVersion(@Param("name") String name, @Param("version") int version);
+
+    @Update(
+            "update h2user set name=#{name} where test_id=#{id}"
+    )
+    int myUpdateWithNameId(@Param("id") Long id, @Param("name") String name);
+
+
+    @Insert(
+            "insert into h2user(name,version) values( #{user1.name}, #{user1.version})"
+    )
+    int myInsertWithParam(@Param("user1") H2UserVersionAndLogicDeleteEntity user1);
+
+    @Insert(
+            "insert into h2user(name,version) values( #{name}, #{version})"
+    )
+    int myInsertWithoutParam(H2UserVersionAndLogicDeleteEntity user1);
+}

+ 16 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2uuidMapper.java

@@ -0,0 +1,16 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import com.baomidou.mybatisplus.test.h2.entity.SuperMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2uuid;
+
+/**
+ * <p>
+ * 测试 uuid 主键
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-06-28
+ */
+public interface H2uuidMapper extends SuperMapper<H2uuid> {
+
+}

+ 29 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/BaseIntVersionEntity.java

@@ -0,0 +1,29 @@
+package com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.io.Serializable;
+
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.Version;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * Base Entity
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@Data
+@Accessors(chain = true)
+public abstract class BaseIntVersionEntity implements Serializable {
+
+    /* 主键ID 注解,value 字段名,type 用户输入ID */
+    @TableId(value = "test_id")
+    private Long id;
+
+    @Version
+    private Integer version;
+}

+ 32 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/BaseSequenceEntity.java

@@ -0,0 +1,32 @@
+package com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import com.baomidou.mybatisplus.annotations.KeySequence;
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.enums.IdType;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@Data
+@Accessors(chain = true)
+@KeySequence("SEQ_TEST")
+public abstract class BaseSequenceEntity {
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    @TableId(value = "TEST_ID", type = IdType.INPUT)
+    private Long id;
+
+}

+ 32 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2Addr.java

@@ -0,0 +1,32 @@
+package com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableName;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * h2address entity.
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/5/25
+ */
+@Data
+@Accessors(chain = true)
+@TableName("h2address")
+public class H2Addr {
+
+    @TableId("addr_id")
+    private Long addrId;
+
+    @TableField("addr_name")
+    private String addrName;
+
+    @TableField("test_id")
+    private Long testId;
+
+}

+ 104 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2User.java

@@ -0,0 +1,104 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.annotations.Version;
+import com.baomidou.mybatisplus.enums.FieldStrategy;
+import com.baomidou.mybatisplus.test.h2.entity.SuperEntity;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 测试用户类
+ * </p>
+ *
+ * @author hubin sjy
+ */
+/* 表名 value 注解【 驼峰命名可无 】, resultMap 注解测试【 映射 xml 的 resultMap 内容 】 */
+@Data
+@Accessors(chain = true)
+@TableName("h2user")
+public class H2User extends SuperEntity {
+
+    /* 测试忽略验证 */
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "test_type", strategy = FieldStrategy.IGNORED)
+    private Integer testType;
+
+    private String desc;
+
+    @TableField("last_updated_dt")
+    private Date lastUpdatedDt;
+
+    @Version
+    private Integer version;
+
+
+    public H2User() {
+
+    }
+
+    public H2User(String name) {
+        this.name = name;
+    }
+
+    public H2User(Integer testType) {
+        this.testType = testType;
+    }
+
+    public H2User(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public H2User(Long id, String name) {
+        this.setId(id);
+        this.name = name;
+    }
+
+    public H2User(Long id, Integer age) {
+        this.setId(id);
+        this.age = age;
+    }
+
+    public H2User(Long id, String name, Integer age, Integer testType) {
+        this.setId(id);
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+    public H2User(String name, Integer age, Integer testType) {
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+}

+ 115 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserDateVersion.java

@@ -0,0 +1,115 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.annotations.Version;
+import com.baomidou.mybatisplus.enums.FieldStrategy;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 测试用户类
+ * </p>
+ *
+ * @author hubin sjy
+ */
+/* 表名 value 注解【 驼峰命名可无 】, resultMap 注解测试【 映射 xml 的 resultMap 内容 】 */
+@Data
+@Accessors(chain = true)
+@TableName("h2user")
+public class H2UserDateVersion implements Serializable {
+
+    /* 表字段注解,false 表中不存在的字段,可无该注解 默认 true */
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    /* 主键ID 注解,value 字段名,type 用户输入ID */
+    @TableId(value = "test_id")
+    private Long id;
+
+    /* 测试忽略验证 */
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "test_type", strategy = FieldStrategy.IGNORED)
+    private Integer testType;
+
+    private String desc;
+
+    private Integer version;
+
+    @TableField(value = "test_date")
+    @Version
+    private Date testDate;
+
+    @TableField("last_updated_dt")
+    private Date lastUpdatedDt;
+
+    public H2UserDateVersion() {
+
+    }
+
+    public H2UserDateVersion(String name) {
+        this.name = name;
+    }
+
+    public H2UserDateVersion(Integer testType) {
+        this.testType = testType;
+    }
+
+    public H2UserDateVersion(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public H2UserDateVersion(Long id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public H2UserDateVersion(Long id, Integer age) {
+        this.id = id;
+        this.age = age;
+    }
+
+    public H2UserDateVersion(Long id, String name, Integer age, Integer testType) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+    public H2UserDateVersion(String name, Integer age, Integer testType) {
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+}

+ 45 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserIntVersionExtendTO.java

@@ -0,0 +1,45 @@
+package com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.enums.FieldStrategy;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@Data
+@Accessors(chain = true)
+@TableName("h2user")
+public class H2UserIntVersionExtendTO extends BaseIntVersionEntity {
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    /* 测试忽略验证 */
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "test_type", strategy = FieldStrategy.IGNORED)
+    private Integer testType;
+
+    private String desc;
+
+
+    @TableField("last_updated_dt")
+    private Date lastUpdatedDt;
+}

+ 58 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserLogicDelete.java

@@ -0,0 +1,58 @@
+package com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableLogic;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.enums.FieldStrategy;
+import com.baomidou.mybatisplus.enums.IdType;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 测试逻辑删除实体
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/15
+ */
+@Data
+@Accessors(chain = true)
+@TableName("h2user")
+public class H2UserLogicDelete {
+
+    /* 表字段注解,false 表中不存在的字段,可无该注解 默认 true */
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    /* 主键ID 注解,value 字段名,type 用户输入ID */
+    @TableId(value = "test_id", type = IdType.AUTO)
+    private Long id;
+
+    /* 测试忽略验证 */
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "test_type", strategy = FieldStrategy.IGNORED)
+    private Integer testType;
+
+    private String desc;
+
+    //    @Version
+    @TableLogic
+    private Integer version;
+
+    @TableField(value = "last_updated_dt")
+    private Timestamp lastUpdatedDt;
+
+}

+ 113 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserMetaObj.java

@@ -0,0 +1,113 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.annotations.Version;
+import com.baomidou.mybatisplus.enums.FieldFill;
+import com.baomidou.mybatisplus.enums.IdType;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 测试用户类
+ * </p>
+ *
+ * @author hubin sjy
+ */
+/* 表名 value 注解【 驼峰命名可无 】, resultMap 注解测试【 映射 xml 的 resultMap 内容 】 */
+@Data
+@Accessors(chain = true)
+@TableName("h2user")
+public class H2UserMetaObj implements Serializable {
+
+    /* 表字段注解,false 表中不存在的字段,可无该注解 默认 true */
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    /* 主键ID 注解,value 字段名,type 用户输入ID */
+    @TableId(value = "test_id", type = IdType.AUTO)
+    private Long id;
+
+    /* 测试忽略验证 */
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "test_type", fill = FieldFill.INSERT)
+    private Integer testType;
+
+    private String desc;
+
+    @Version
+    private Integer version;
+    @TableField(value = "last_updated_dt")
+    private Timestamp lastUpdatedDt;
+
+
+    public H2UserMetaObj() {
+
+    }
+
+    public H2UserMetaObj(String name) {
+        this.name = name;
+    }
+
+    public H2UserMetaObj(Integer testType) {
+        this.testType = testType;
+    }
+
+    public H2UserMetaObj(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public H2UserMetaObj(Long id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public H2UserMetaObj(Long id, Integer age) {
+        this.id = id;
+        this.age = age;
+    }
+
+    public H2UserMetaObj(Long id, String name, Integer age, Integer testType) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+    public H2UserMetaObj(String name, Integer age, Integer testType) {
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+}

+ 110 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserNoVersion.java

@@ -0,0 +1,110 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.enums.FieldStrategy;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 测试用户类
+ * </p>
+ *
+ * @author hubin sjy
+ */
+/* 表名 value 注解【 驼峰命名可无 】, resultMap 注解测试【 映射 xml 的 resultMap 内容 】 */
+@Data
+@Accessors(chain = true)
+@TableName("h2user")
+public class H2UserNoVersion implements Serializable {
+
+    /* 表字段注解,false 表中不存在的字段,可无该注解 默认 true */
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    /* 主键ID 注解,value 字段名,type 用户输入ID */
+    @TableId(value = "test_id")
+    private Long id;
+
+    /* 测试忽略验证 */
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "test_type", strategy = FieldStrategy.IGNORED)
+    private Integer testType;
+
+    private String desc;
+
+    private Integer version;
+
+    @TableField("last_updated_dt")
+    private Date lastUpdatedDt;
+
+    public H2UserNoVersion() {
+
+    }
+
+    public H2UserNoVersion(String name) {
+        this.name = name;
+    }
+
+    public H2UserNoVersion(Integer testType) {
+        this.testType = testType;
+    }
+
+    public H2UserNoVersion(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public H2UserNoVersion(Long id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public H2UserNoVersion(Long id, Integer age) {
+        this.id = id;
+        this.age = age;
+    }
+
+    public H2UserNoVersion(Long id, String name, Integer age, Integer testType) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+    public H2UserNoVersion(String name, Integer age, Integer testType) {
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+}

+ 22 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserSeq.java

@@ -0,0 +1,22 @@
+package com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import com.baomidou.mybatisplus.annotations.KeySequence;
+import com.baomidou.mybatisplus.annotations.TableName;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@Data
+@Accessors(chain = true)
+@TableName("h2user")
+@KeySequence("SEQ_TEST")
+public class H2UserSeq {
+
+}

+ 61 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserSequence.java

@@ -0,0 +1,61 @@
+package com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.math.BigDecimal;
+
+import com.baomidou.mybatisplus.annotations.KeySequence;
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.annotations.Version;
+import com.baomidou.mybatisplus.enums.FieldStrategy;
+import com.baomidou.mybatisplus.enums.IdType;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@Data
+@Accessors(chain = true)
+@TableName("h2user")
+@KeySequence("SEQ_TEST")
+public class H2UserSequence {
+
+
+    public H2UserSequence() {
+    }
+
+    public H2UserSequence(String name, Integer version) {
+        this.name = name;
+        this.version = version;
+    }
+
+    /**
+     * 主键ID
+     */
+    @TableId(value = "TEST_ID", type = IdType.INPUT)
+    private Long id;
+
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "test_type", strategy = FieldStrategy.IGNORED)
+    private Integer testType;
+
+    private String desc;
+
+    @Version
+    private Integer version;
+
+
+}

+ 50 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserSequenceExtendTO.java

@@ -0,0 +1,50 @@
+package com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.math.BigDecimal;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.annotations.Version;
+import com.baomidou.mybatisplus.enums.FieldStrategy;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@Data
+@Accessors(chain = true)
+@TableName("h2user")
+public class H2UserSequenceExtendTO extends BaseSequenceEntity {
+
+    public H2UserSequenceExtendTO() {
+    }
+
+    public H2UserSequenceExtendTO(String name, Integer version) {
+        this.name = name;
+        this.version = version;
+    }
+
+    /* 测试忽略验证 */
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "test_type", strategy = FieldStrategy.IGNORED)
+    private Integer testType;
+
+    private String desc;
+
+    @Version
+    private Integer version;
+
+}

+ 117 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserVersionAndLogicDeleteEntity.java

@@ -0,0 +1,117 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableLogic;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.annotations.Version;
+import com.baomidou.mybatisplus.enums.FieldStrategy;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 测试用户类
+ * </p>
+ *
+ * @author hubin sjy
+ */
+/* 表名 value 注解【 驼峰命名可无 】, resultMap 注解测试【 映射 xml 的 resultMap 内容 】 */
+@Data
+@Accessors(chain = true)
+@TableName("h2user")
+public class H2UserVersionAndLogicDeleteEntity implements Serializable {
+
+    /* 表字段注解,false 表中不存在的字段,可无该注解 默认 true */
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    /* 主键ID 注解,value 字段名,type 用户输入ID */
+    @TableId(value = "test_id")
+    private Long id;
+
+    /* 测试忽略验证 */
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "test_type", strategy = FieldStrategy.IGNORED)
+    private Integer testType;
+
+    private String desc;
+
+    @TableLogic
+    private Integer version;
+
+    @TableField(value = "test_date")
+    @Version
+    private Date testDate;
+
+    @TableField("last_updated_dt")
+    private Date lastUpdatedDt;
+
+    public H2UserVersionAndLogicDeleteEntity() {
+
+    }
+
+    public H2UserVersionAndLogicDeleteEntity(String name) {
+        this.name = name;
+    }
+
+    public H2UserVersionAndLogicDeleteEntity(Integer testType) {
+        this.testType = testType;
+    }
+
+    public H2UserVersionAndLogicDeleteEntity(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public H2UserVersionAndLogicDeleteEntity(Long id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public H2UserVersionAndLogicDeleteEntity(Long id, Integer age) {
+        this.id = id;
+        this.age = age;
+    }
+
+    public H2UserVersionAndLogicDeleteEntity(Long id, String name, Integer age, Integer testType) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+    public H2UserVersionAndLogicDeleteEntity(String name, Integer age, Integer testType) {
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+}

+ 59 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2uuid.java

@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.io.Serializable;
+
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.enums.IdType;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 测试 UUID 主键
+ * </p>
+ *
+ * @author hubin
+ * @Date 2017-06-28
+ */
+@Data
+@Accessors(chain = true)
+@TableName("h2uuid")
+public class H2uuid implements Serializable {
+
+    // 静态属性会自动忽略
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @TableId(type = IdType.UUID)
+    private String id;
+
+    private String type;
+
+    public H2uuid() {
+
+    }
+
+    public H2uuid(String type) {
+        this.type = type;
+    }
+
+}

+ 16 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserExtendsService.java

@@ -0,0 +1,16 @@
+package com.baomidou.mybatisplus.test.h2.service;
+
+import com.baomidou.mybatisplus.service.IService;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserIntVersionExtendTO;
+
+/**
+ * <p>
+ * 实体继承id,version
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+public interface IH2UserExtendsService extends IService<H2UserIntVersionExtendTO> {
+
+}

+ 16 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserLogicDeleteService.java

@@ -0,0 +1,16 @@
+package com.baomidou.mybatisplus.test.h2.service;
+
+import com.baomidou.mybatisplus.service.IService;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserLogicDelete;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/15
+ */
+public interface IH2UserLogicDeleteService extends IService<H2UserLogicDelete> {
+
+    public H2UserLogicDelete selectByIdMy(Long id);
+}

+ 15 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserMetaobjService.java

@@ -0,0 +1,15 @@
+package com.baomidou.mybatisplus.test.h2.service;
+
+import com.baomidou.mybatisplus.service.IService;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserMetaObj;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/27
+ */
+public interface IH2UserMetaobjService extends IService<H2UserMetaObj> {
+
+}

+ 31 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserNoVersionService.java

@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.h2.service;
+
+import com.baomidou.mybatisplus.service.IService;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserNoVersion;
+
+/**
+ * <p>
+ * Service层测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-01-30
+ */
+public interface IH2UserNoVersionService extends IService<H2UserNoVersion> {
+
+}

+ 15 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserSequenceExtendsService.java

@@ -0,0 +1,15 @@
+package com.baomidou.mybatisplus.test.h2.service;
+
+import com.baomidou.mybatisplus.service.IService;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserSequenceExtendTO;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+public interface IH2UserSequenceExtendsService extends IService<H2UserSequenceExtendTO> {
+
+}

+ 15 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserSequenceService.java

@@ -0,0 +1,15 @@
+package com.baomidou.mybatisplus.test.h2.service;
+
+import com.baomidou.mybatisplus.service.IService;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserSequence;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+public interface IH2UserSequenceService extends IService<H2UserSequence> {
+
+}

+ 48 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserService.java

@@ -0,0 +1,48 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.h2.service;
+
+import java.util.List;
+import java.util.Map;
+
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.service.IService;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2User;
+
+/**
+ * <p>
+ * Service层测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-01-30
+ */
+public interface IH2UserService extends IService<H2User> {
+
+    int myInsert(String name, int version);
+
+    int myInsertWithParam(String name, int version);
+
+    int myInsertWithoutParam(String name, int version);
+
+    int myUpdate(Long id, String name);
+
+    List<H2User> queryWithParamInSelectStatememt(Map<String,Object> param);
+
+    Page<H2User> queryWithParamInSelectStatememt4Page(Map<String,Object> param, Page<H2User> page);
+
+    int selectCountWithParamInSelectItems(Map<String,Object> param);
+}

+ 20 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserExtendsServiceImpl.java

@@ -0,0 +1,20 @@
+package com.baomidou.mybatisplus.test.h2.service.impl;
+
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserExtendsMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserIntVersionExtendTO;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserExtendsService;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@Service
+public class H2UserExtendsServiceImpl extends ServiceImpl<H2UserExtendsMapper, H2UserIntVersionExtendTO> implements IH2UserExtendsService {
+
+}

+ 29 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserLogicDeleteServiceImpl.java

@@ -0,0 +1,29 @@
+package com.baomidou.mybatisplus.test.h2.service.impl;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserLogicDeleteMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserLogicDelete;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserLogicDeleteService;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/15
+ */
+@Service
+public class H2UserLogicDeleteServiceImpl extends ServiceImpl<H2UserLogicDeleteMapper, H2UserLogicDelete> implements IH2UserLogicDeleteService {
+
+    @Autowired
+    H2UserLogicDeleteMapper userLogicDeleteMapper;
+
+
+    @Override
+    public H2UserLogicDelete selectByIdMy(Long id) {
+        return userLogicDeleteMapper.selectByIdMy(id);
+    }
+}

+ 20 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserMetaobjServiceImpl.java

@@ -0,0 +1,20 @@
+package com.baomidou.mybatisplus.test.h2.service.impl;
+
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserMetaobjMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserMetaObj;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserMetaobjService;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/27
+ */
+@Service
+public class H2UserMetaobjServiceImpl extends ServiceImpl<H2UserMetaobjMapper, H2UserMetaObj> implements IH2UserMetaobjService {
+
+}

+ 36 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserNoVersionServiceImpl.java

@@ -0,0 +1,36 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.h2.service.impl;
+
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserNoVersionMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserNoVersion;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserNoVersionService;
+
+/**
+ * <p>
+ * Service层测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-01-30
+ */
+@Service
+public class H2UserNoVersionServiceImpl extends ServiceImpl<H2UserNoVersionMapper, H2UserNoVersion> implements IH2UserNoVersionService {
+
+}

+ 20 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserSequenceExtendsServiceImpl.java

@@ -0,0 +1,20 @@
+package com.baomidou.mybatisplus.test.h2.service.impl;
+
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserSequenceExtendsMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserSequenceExtendTO;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserSequenceExtendsService;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@Service
+public class H2UserSequenceExtendsServiceImpl extends ServiceImpl<H2UserSequenceExtendsMapper, H2UserSequenceExtendTO> implements IH2UserSequenceExtendsService {
+
+}

+ 20 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserSequenceServiceImpl.java

@@ -0,0 +1,20 @@
+package com.baomidou.mybatisplus.test.h2.service.impl;
+
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserSequenceMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserSequence;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserSequenceService;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/26
+ */
+@Service
+public class H2UserSequenceServiceImpl extends ServiceImpl<H2UserSequenceMapper, H2UserSequence> implements IH2UserSequenceService {
+
+}

+ 86 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserServiceImpl.java

@@ -0,0 +1,86 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.h2.service.impl;
+
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2User;
+import com.baomidou.mybatisplus.test.h2.service.IH2UserService;
+
+/**
+ * <p>
+ * Service层测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-01-30
+ */
+@Service
+public class H2UserServiceImpl extends ServiceImpl<H2UserMapper, H2User> implements IH2UserService {
+
+    @Autowired
+    H2UserMapper userMapper;
+
+    @Override
+    public int myInsert(String name, int version) {
+        return userMapper.myInsertWithNameVersion(name, version);
+    }
+
+    @Override
+    public int myInsertWithParam(String name, int version) {
+        H2User user = new H2User();
+        user.setName(name);
+        user.setVersion(version);
+        return userMapper.myInsertWithParam(user);
+    }
+
+    @Override
+    public int myInsertWithoutParam(String name, int version) {
+        H2User user = new H2User();
+        user.setName(name);
+        user.setVersion(version);
+        return userMapper.myInsertWithoutParam(user);
+    }
+
+    @Override
+    public int myUpdate(Long id, String name) {
+        return userMapper.myUpdateWithNameId(id, name);
+    }
+
+    @Override
+    public List<H2User> queryWithParamInSelectStatememt(Map<String, Object> param) {
+        return userMapper.selectUserWithParamInSelectStatememt(param);
+    }
+
+    @Override
+    public Page<H2User> queryWithParamInSelectStatememt4Page(Map<String, Object> param, Page<H2User> page) {
+        page.setSearchCount(true);
+        userMapper.selectUserWithParamInSelectStatememt4Page(param, page);
+        return page;
+    }
+
+    @Override
+    public int selectCountWithParamInSelectItems(Map<String, Object> param) {
+        return userMapper.selectCountWithParamInSelectItems(param);
+    }
+}

+ 63 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/CircularLabelsTest.java

@@ -0,0 +1,63 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.ibatis.session.SqlSession;
+
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.CrudTest;
+import com.baomidou.mybatisplus.test.mysql.entity.Test;
+import com.baomidou.mybatisplus.test.mysql.entity.User;
+import com.baomidou.mybatisplus.test.mysql.mapper.TestMapper;
+import com.baomidou.mybatisplus.test.mysql.mapper.UserMapper;
+
+/**
+ * <p>
+ * 循环标签 查询分页失效 测试类
+ * </p>
+ *
+ * @author Caratacus
+ * @Date 2016-12-21
+ */
+public class CircularLabelsTest extends CrudTest {
+
+    /**
+     * 循环标签 测试
+     */
+    @org.junit.Test
+    public void test() {
+        SqlSession session = this.sqlSessionFactory().openSession();
+        UserMapper userMapper = session.getMapper(UserMapper.class);
+        Page<User> page = new Page<>(1, 6);
+        List<User> users = userMapper.forSelect(page, Arrays.asList("1", "2", "3"));
+        System.out.println(users.toString());
+        System.out.println(page);
+        User user = new User();
+        user.setId(1L);
+        User users1 = userMapper.selectOne(user);
+        System.out.println(users1);
+        TestMapper mapper = session.getMapper(TestMapper.class);
+        Test test = new Test();
+        test.setCreateTime(new Date());
+        test.setType("11111");
+        mapper.insert(test);
+        session.rollback();
+    }
+}

+ 84 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/LogicDeleteTest.java

@@ -0,0 +1,84 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.session.SqlSession;
+import org.junit.Test;
+
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.mapper.Condition;
+import com.baomidou.mybatisplus.test.CrudTest;
+import com.baomidou.mybatisplus.test.mysql.entity.User;
+import com.baomidou.mybatisplus.test.mysql.mapper.UserMapper;
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+
+/**
+ * <p>
+ * 逻辑删除测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-09-09
+ */
+public class LogicDeleteTest extends CrudTest {
+
+    @Override
+    public GlobalConfiguration globalConfiguration() {
+        GlobalConfiguration gc = super.globalConfiguration();
+        gc.setLogicDeleteValue("-1");// 逻辑删除值 -1 测试字段 type
+        return gc;
+    }
+
+    @Test
+    public void test() {
+        // 加载配置文件
+        SqlSession session = this.sqlSessionFactory().openSession();
+        UserMapper userMapper = session.getMapper(UserMapper.class);
+        System.err.println(" debug run 查询执行 user 表数据变化! ");
+        long id = IdWorker.getId();
+        int rlt = userMapper.insert(new User(id, "logic-delete-1", 18, 1));
+        System.err.println("插入成功记录数:" + rlt);
+        rlt = userMapper.deleteById(id);
+        System.err.println("根据 ID 逻辑删除成功记录数:" + rlt);
+
+        User uu = new User();
+        uu.setId(333L);
+        uu.setTestType(1);
+        System.err.println("第一次:逻辑删除testType 改为 1 成功记录数:" + rlt);
+        rlt = userMapper.insert(new User(IdWorker.getId(), "logic-delete-2", 28, 2));
+        System.err.println("再插入一条成功记录数:" + rlt);
+        rlt = userMapper.delete(Condition.create().eq("test_id", 1111));
+        System.err.println("全表逻辑删除成功记录数:" + rlt);
+        List<User> userList = userMapper.selectList(null);
+        for (User u : userList) {
+            System.out.println("全表逻辑删除 ( id= " + u.getId() + " ) 展示结果" + u.getTestType());
+        }
+
+        System.err.println("第二次:逻辑删除testType 改为 1 成功记录数:" + rlt);
+        Map<String, Object> map = new HashMap<>();
+        map.put("test_id", id);
+        rlt = userMapper.deleteByMap(map);
+        System.err.println("全表逻辑删除 ByMap 成功记录数:" + rlt);
+        userList = userMapper.selectList(null);
+        for (User u : userList) {
+            System.out.println("全表逻辑删除 ( id= " + u.getId() + " ) 展示结果" + u.getTestType());
+        }
+    }
+}

+ 34 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/MyBaseMapper.java

@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+
+/**
+ * <p>
+ * 自定义 Mapper 接口
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-03-14
+ */
+public interface MyBaseMapper<T> extends BaseMapper<T> {
+
+    // 测试自定义 Mapper 接口
+
+    // 这个类  不要放到  mapper 扫描目录,否则会当做真实 表 mapper 扫描异常!!
+
+}

+ 59 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/MyMetaObjectHandler.java

@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql;
+
+import org.apache.ibatis.reflection.MetaObject;
+
+import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
+
+/**
+ * <p>
+ * 测试,自定义元对象字段填充控制器,实现公共字段自动写入
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-08-28
+ */
+public class MyMetaObjectHandler extends MetaObjectHandler {
+
+    /**
+     * 测试 user 表 name 字段为空自动填充
+     */
+    public void insertFill(MetaObject metaObject) {
+        // 测试下划线
+        Object testType = getFieldValByName("testType", metaObject);
+        System.out.println("testType=" + testType);
+        if (testType == null) {// 如果不会设置这里不需要判断, 直接 set
+            System.out.println("*************************");
+            System.out.println("insert fill");
+            System.out.println("*************************");
+            setFieldValByName("testType", 3, metaObject);
+        }
+    }
+
+    @Override
+    public boolean openUpdateFill() {
+        System.out.println("*************************");
+        System.out.println(" 关闭更新填充 ");
+        System.out.println("*************************");
+        return false;
+    }
+
+    @Override
+    public void updateFill(MetaObject metaObject) {
+        // 这里不会执行
+    }
+}

+ 67 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/MySqlInjector.java

@@ -0,0 +1,67 @@
+/**
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql;
+
+import org.apache.ibatis.builder.MapperBuilderAssistant;
+import org.apache.ibatis.mapping.SqlSource;
+import org.apache.ibatis.session.Configuration;
+
+import com.baomidou.mybatisplus.entity.TableInfo;
+import com.baomidou.mybatisplus.mapper.AutoSqlInjector;
+
+/**
+ * <p>
+ * 测试自定义注入 SQL
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-07-23
+ */
+public class MySqlInjector extends AutoSqlInjector {
+
+    @Override
+    public void inject(Configuration configuration, MapperBuilderAssistant builderAssistant, Class<?> mapperClass,
+                       Class<?> modelClass, TableInfo table) {
+        /* 添加一个自定义方法 */
+        deleteAllUser(mapperClass, modelClass, table);
+        // 测试 com.baomidou.mybatisplus.test.mysql.MetaObjectHandlerTest
+        deleteLogicById(mapperClass, modelClass, table);
+    }
+
+    public void deleteAllUser(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
+
+		/* 执行 SQL ,动态 SQL 参考类 SqlMethod */
+        String sql = "delete from " + table.getTableName();
+
+		/* mapper 接口方法名一致 */
+        String method = "deleteAll";
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        this.addDeleteMappedStatement(mapperClass, method, sqlSource);
+    }
+
+    public void deleteLogicById(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
+
+		/* 执行 SQL ,动态 SQL 参考类 SqlMethod */
+        String sql = String.format("UPDATE %s SET test_type=-1 WHERE test_id=#{id}", table.getTableName());
+
+		/* mapper 接口方法名一致 */
+        String method = "deleteLogicById";
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+
+        // 注意!! 这里是更新、删除、插入、调用方法注入不一样!!
+        this.addUpdateMappedStatement(mapperClass, modelClass, method, sqlSource);
+    }
+}

+ 70 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/NoXMLTest.java

@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.session.RowBounds;
+import org.apache.ibatis.session.SqlSession;
+
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.CrudTest;
+import com.baomidou.mybatisplus.test.mysql.entity.Test;
+import com.baomidou.mybatisplus.test.mysql.mapper.TestMapper;
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+
+/**
+ * <p>
+ * 测试没有XML同样注入CRUD SQL
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2016-09-26
+ */
+public class NoXMLTest extends CrudTest {
+
+    @org.junit.Test
+    public void test() {
+        SqlSession sqlSession = this.sqlSessionFactory().openSession();
+        /**
+         * 查询是否有结果
+         */
+        TestMapper testMapper = sqlSession.getMapper(TestMapper.class);
+        testMapper.insert(new Test(IdWorker.getId(), "Caratacus"));
+        List<Map<String, Object>> list = testMapper.selectMaps(null);
+        List<Map<String, Object>> list1 = testMapper.selectMapsPage(RowBounds.DEFAULT, null);
+        List<Map<String, Object>> list2 = testMapper.selectMapsPage(new Page<>(1, 5), null);
+        System.out.println(list);
+        System.out.println(list1);
+        System.out.println(list2);
+        Map<String, Object> map = new HashMap<>();
+        map.put("type", null);
+        map.put("id", null);
+        List<Test> tests = testMapper.selectByMap(map);
+        if (null != tests) {
+            for (Test test : tests) {
+                System.out.println("id:" + test.getId() + " , type:" + test.getType());
+            }
+        } else {
+            System.err.println(" tests is null. ");
+        }
+        testMapper.delete(null);
+
+    }
+
+}

+ 55 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/ServiceImplTest.java

@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.baomidou.mybatisplus.test.mysql.entity.User;
+import com.baomidou.mybatisplus.test.mysql.service.IUserService;
+
+/**
+ * <p>
+ * Service层测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-01-30
+ */
+//@RunWith(SpringJUnit4ClassRunner.class)
+//@ContextConfiguration({ "classpath:spring/spring-servlet.xml" })
+public class ServiceImplTest {
+
+    @Autowired
+    private IUserService userService;
+
+    //@Test
+    public void testInsertBatch() throws IOException {
+        List<User> userList = new ArrayList<>();
+        for (int i = 0; i < 10; i++) {
+            userList.add(new User("u-" + i, i, i));
+        }
+        boolean batchResult = userService.insertBatch(userList);
+        System.err.println("batchResult: " + batchResult);
+
+        // 注入测试
+        userService.testSqlInjector();
+    }
+
+}

+ 75 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/SqlRunnerTest.java

@@ -0,0 +1,75 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql;
+
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.baomidou.mybatisplus.mapper.SqlRunner;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.CrudTest;
+import com.baomidou.mybatisplus.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
+
+/**
+ * <p>
+ * 测试SqlRunner
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2016-12-19
+ */
+public class SqlRunnerTest extends CrudTest {
+
+    @Test
+    public void test1() {
+        /*
+         * 加载配置文件
+		 */
+        TableInfoHelper.initSqlSessionFactory(this.sqlSessionFactory());
+
+        boolean b = SqlRunner.db().insert("INSERT INTO `test` (`id`, `type`) VALUES ('107880983085826048', 't1021')");
+        System.out.println(b);
+        Assert.assertTrue(b);
+        boolean b1 = SqlRunner.db().update("UPDATE `test` SET `type`='tttttttt' WHERE (`id`=107880983085826048)");
+        System.out.println(b1);
+
+        Assert.assertTrue(b1);
+        List<Map<String, Object>> maps = SqlRunner.db().selectList("select * from test WHERE (`id`=107880983085826048)");
+        System.out.println(maps);
+        String type = (String) maps.get(0).get("type");
+        System.out.println(type);
+        Assert.assertEquals("tttttttt", type);
+        boolean b2 = SqlRunner.db().delete("DELETE from test WHERE (`id`=107880983085826048)");
+        System.out.println(b2);
+        Assert.assertTrue(b2);
+        List<Map<String, Object>> maps1 = SqlRunner.db().selectList("select * from test WHERE (`id`=107880983085826048)");
+        System.out.println(maps1);
+        if (CollectionUtils.isEmpty(maps1)) {
+            maps1 = null;
+        }
+        Assert.assertNull(maps1);
+        Page<Map<String, Object>> mapPage = SqlRunner.db().selectPage(new Page<>(1, 5), "select * from test ");
+        System.out.println(mapPage);
+        int i = SqlRunner.db().selectCount("select count(0) from test ");
+        System.out.println("count:" + i);
+
+    }
+
+}

+ 57 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/TransactionalTest.java

@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql;
+
+import org.apache.ibatis.session.SqlSession;
+import org.junit.Test;
+
+import com.baomidou.mybatisplus.test.CrudTest;
+import com.baomidou.mybatisplus.test.mysql.entity.User;
+import com.baomidou.mybatisplus.test.mysql.mapper.UserMapper;
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+
+/**
+ * <p>
+ * MySQL 数据库,表引擎  MyISAM  不支持事务,请使用  InnoDB  !!!!
+ * </p>
+ *
+ * @author hubin
+ * @date 2016-09-20
+ */
+public class TransactionalTest extends CrudTest {
+
+    /**
+     * <p>
+     * 事务测试
+     * </p>
+     */
+    @Test
+    public void test() {
+        SqlSession sqlSession = this.sqlSessionFactory().openSession();
+
+        /**
+         * 插入
+         */
+        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
+        int rlt = userMapper.insert(new User(IdWorker.getId(), "1", 1, 1));
+        System.err.println("--------- insertInjector --------- " + rlt);
+
+        //session.commit();
+        sqlSession.rollback();
+        sqlSession.close();
+    }
+
+}

+ 108 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/URPTest.java

@@ -0,0 +1,108 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql;
+
+import java.util.List;
+
+import org.apache.ibatis.session.SqlSession;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.test.CrudTest;
+import com.baomidou.mybatisplus.test.mysql.entity.PhoneNumber;
+import com.baomidou.mybatisplus.test.mysql.entity.Role;
+import com.baomidou.mybatisplus.test.mysql.entity.User;
+import com.baomidou.mybatisplus.test.mysql.mapper.RoleMapper;
+import com.baomidou.mybatisplus.test.mysql.mapper.UserMapper;
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+
+/**
+ * <p>
+ * 对User, Role及el, typeHandler, resultMap进行测试
+ * </p>
+ *
+ * @author junyu
+ * @Date 2016-09-09
+ */
+public class URPTest extends CrudTest {
+
+    @Test
+    public void crossResultMapTest() {
+        // 加载配置文件
+        SqlSession session = this.sqlSessionFactory().openSession();
+        RoleMapper roleMapper = session.getMapper(RoleMapper.class);
+        Role role = new Role();
+        role.setName("K 神");
+        role.setDescription("无敌战神 K");
+        role.setSort(2);
+        roleMapper.insert(role);
+        UserMapper userMapper = session.getMapper(UserMapper.class);
+        List<Role> roles = userMapper.selectRoleList();
+        Assert.assertTrue(roles.size() >= 1);
+    }
+
+    @Test
+    public void urpTest() {
+        // 加载配置文件
+        SqlSession session = this.sqlSessionFactory().openSession();
+
+        UserMapper userMapper = session.getMapper(UserMapper.class);
+        RoleMapper roleMapper = session.getMapper(RoleMapper.class);
+
+        /**
+         * sjy 测试@TableField的el属性, 级联resultMap
+         */
+        Role role = new Role();
+        role.setId(IdWorker.getId());
+        role.setName("admin");
+        int rlt = roleMapper.insert(role);
+        System.err.println("--------- insert role --------- " + rlt);
+
+        PhoneNumber phone = new PhoneNumber("81", "0576", "82453832");
+
+        User userA = new User();
+        userA.setId(IdWorker.getId());
+        userA.setName("junyu_shi");
+        userA.setAge(15);
+        userA.setTestType(1);
+        userA.setRole(role);
+        userA.setPhone(phone);
+        rlt = userMapper.insert(userA);
+        System.err.println("--------- insert user --------- " + rlt);
+
+        User whereUser = userMapper.selectOne(userA);
+        System.err.println("--------- select user --------- " + whereUser.toString());
+
+        // 如果不使用el表达式, User类中就同时需要roleId用于对应User表中的字段,
+        // 和Role属性用于保存resultmap的级联查询. 在插入时, 就需要写user.setRoleId(), 然后updateUser.
+        role = new Role();
+        role.setId(IdWorker.getId());
+        role.setName("root");
+        roleMapper.insert(role);
+        userA.setRole(role);
+        userMapper.updateById(userA);
+        System.err.println("--------- upadte user's role --------- " + rlt);
+
+        whereUser = userMapper.selectOne(userA);
+        System.err.println("--------- select user --------- " + whereUser.toString());
+
+        userMapper.delete(new EntityWrapper<>(userA));
+        System.err.println("--------- delete user --------- " + rlt);
+
+    }
+
+}

+ 334 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/UserMapperTest.java

@@ -0,0 +1,334 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.session.SqlSession;
+import org.junit.Test;
+
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.plugins.pagination.Pagination;
+import com.baomidou.mybatisplus.test.CrudTest;
+import com.baomidou.mybatisplus.test.mysql.entity.Role;
+import com.baomidou.mybatisplus.test.mysql.entity.User;
+import com.baomidou.mybatisplus.test.mysql.mapper.UserMapper;
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+
+/**
+ * <p>
+ * MybatisPlus 测试类
+ * </p>
+ * <p>
+ * 自动提交了事务问题:<br>
+ * http://www.mybatis.org/spring/transactions.html#programmatic<br>
+ * https://github.com/mybatis/spring/issues/39<br>
+ * </p>
+ *
+ * @author hubin sjy
+ * @Date 2016-01-23
+ */
+public class UserMapperTest extends CrudTest {
+
+    @Override
+    public GlobalConfiguration globalConfiguration() {
+        GlobalConfiguration gc = super.globalConfiguration();
+        /**
+         * 设置,自定义 元对象填充器,实现公共字段自动写入
+         */
+        gc.setMetaObjectHandler(new MyMetaObjectHandler());
+        // gc.setCapitalMode(true);
+        gc.setDbColumnUnderline(true);
+        return gc;
+    }
+
+    /**
+     * RUN 测试
+     * <p>
+     * <p>
+     * MybatisPlus 加载 SQL 顺序:
+     * </p>
+     * 1、加载XML中的SQL<br>
+     * 2、加载sqlProvider中的SQL<br>
+     * 3、xmlSql 与 sqlProvider不能包含相同的SQL<br>
+     * <br>
+     * 调整后的SQL优先级:xmlSql > sqlProvider > crudSql <br>
+     */
+    @Test
+    public void crudTest() {
+        SqlSession session = this.sqlSessionFactory().openSession();
+        UserMapper userMapper = session.getMapper(UserMapper.class);
+        System.err.println(" debug run 查询执行 user 表数据变化! ");
+        userMapper.deleteAll();
+
+        /**
+         * sjy 测试@TableField的el属性
+         */
+        Role role = new Role();
+        role.setId(IdWorker.getId());
+        role.setName("admin");
+
+        User userA = new User();
+        userA.setId(IdWorker.getId());
+        userA.setName("junyu_shi");
+        userA.setAge(1);
+        userA.setDesc("测试一把");
+        userA.setTestType(1);
+        userA.setRole(role);
+
+        int rlt = userMapper.insert(userA);
+        User whereUser = userMapper.selectOne(userA);
+        print(whereUser);
+
+        userA.setAge(18);
+        userMapper.updateById(userA);
+        userMapper.delete(new EntityWrapper<>(userA));
+        System.err.println("--------- @TableField el() --------- " + rlt);
+
+        /**
+         * 注解插件测试
+         */
+        rlt = userMapper.insertInjector(new User(1L, "1", 1, 1));
+        System.err.println("--------- insertInjector --------- " + rlt);
+
+        /**
+         * ehcache 缓存测试
+         */
+        User cacheUser = userMapper.selectOne(new User(1L, 1));
+        print(cacheUser);
+        cacheUser = userMapper.selectOne(new User(1L, 1));
+        print(cacheUser);
+
+        /**
+         * 插入
+         */
+        long id = IdWorker.getId();
+        rlt = userMapper.insert(new User(id, "abc", 18, 1));
+        System.err.println("\n--------------insert-------" + rlt);
+        sleep();
+
+        rlt = userMapper.insert(new User(18));
+        System.err.println("\n----------测试 name 字段忽略验证----insert-------" + rlt);
+        sleep();
+
+        List<User> ul = new ArrayList<>();
+
+		/* 手动输入 ID */
+        ul.add(new User(11L, "1", 1, 0));
+        ul.add(new User(12L, "2", 2, 1));
+        ul.add(new User(13L, "3", 3, 1));
+        ul.add(new User(14L, "delname", 4, 0));
+        ul.add(new User(15L, "5", 5, 1));
+        ul.add(new User(16L, "6", 6, 0));
+
+		/* 测试 name test_type 填充 */
+        ul.add(new User(17L, 7));
+        ul.add(new User(18L, 8));
+        ul.add(new User(19L, 9));
+        ul.add(new User(7));
+        ul.add(new User(20L, "deleteByMap", 7, 0));
+
+		/* 使用 ID_WORKER 自动生成 ID */
+        ul.add(new User("8", 8, 1));
+        ul.add(new User("9", 9, 1));
+        for (User u : ul) {
+            rlt = userMapper.insert(u);
+        }
+        System.err.println("\n--------------insertBatch----------------" + rlt + "\n\n");
+        System.err.println("\n 自定义填充 testType=3 填充成功!" + userMapper.selectById(18L).toString());
+
+        /**
+         * 提交,往下操作在一个事物中!!!
+         */
+        session.commit();
+
+		/*
+         * 删除
+		 */
+        rlt = userMapper.deleteById(id);
+        System.err.println("---------deleteById------- delete id=" + id + " ,result=" + rlt + "\n\n");
+        sleep();
+
+        Map<String, Object> columnMap = new HashMap<>();
+        columnMap.put("name", "deleteByMap");
+        columnMap.put("age", null);
+        rlt = userMapper.deleteByMap(columnMap);
+        System.err.println("---------deleteByMap------- result=" + rlt + "\n\n");
+        sleep();
+
+        List<Long> il = new ArrayList<>();
+        il.add(16L);
+        il.add(17L);
+        rlt = userMapper.deleteBatchIds(il);
+        System.err.println("---------deleteBatchIds------- delete id=" + id + " ,result=" + rlt + "\n\n");
+        sleep();
+
+        rlt = userMapper.delete(new EntityWrapper<>(new User(14L, "delname")));
+        System.err.println("--------------delete------------------ result=" + rlt + "\n\n");
+        sleep();
+
+		/*
+         * <p> 修改 </p>
+		 *
+		 * updateById 是从 SuperMapper 中继承而来的,UserMapper.xml中并没有申明改sql
+		 */
+        rlt = userMapper.updateById(new User(12L, "MybatisPlus"));
+        System.err.println("------------------updateById---------------------- result=" + rlt + "\n\n");
+        sleep();
+
+        rlt = userMapper.updateById(new User(12L, "update all column", 12, 12));
+        System.err.println("------------------updateById---------------------- result=" + rlt + "\n\n");
+        sleep();
+
+        rlt = userMapper.update(new User("55", 55, 5), new EntityWrapper<>(new User(15L, "5")));
+        System.err.println("------------------update---------------------- result=" + rlt + "\n\n");
+        sleep();
+
+        EntityWrapper<User> ew1 = new EntityWrapper<>();
+        ew1.addFilter("test_id={0} AND name={1}", 15L, "55");
+        rlt = userMapper.update(new User("00"), ew1);
+        System.err.println("------------------update---------------------- result=" + rlt + "\n\n");
+        sleep();
+
+		/* 无条件选择更新 */
+        // userMapper.update(new User("11"), null);
+
+        List<User> userList = new ArrayList<>();
+        userList.add(new User(11L, "updateBatchById-1", 1, 1));
+        userList.add(new User(12L, "updateBatchById-2", 2, 1));
+        userList.add(new User(13L, "updateBatchById-3", 3, 1));
+        for (User u : userList) {
+            rlt = userMapper.updateById(u);
+        }
+        System.err.println("------------------updateBatchById---------------------- result=" + rlt + "\n\n");
+        sleep();
+
+		/*
+         * <p> 查询 </p>
+		 */
+        System.err.println("\n------------------selectById----------------------");
+        User user = userMapper.selectById(12L);
+        print(user);
+
+        System.err.println("\n------------------selectBatchIds----------------------");
+        List<Long> idList = new ArrayList<>();
+        idList.add(11L);
+        idList.add(12L);
+        List<User> ul0 = userMapper.selectBatchIds(idList);
+        for (User anUl0 : ul0) {
+            print(anUl0);
+        }
+
+        System.err.println("\n------------------selectByMap-----满足 map 条件的数据----");
+        Map<String, Object> cm = new HashMap<>();
+        cm.put("test_type", 1);
+        cm.put("1", 1);
+        List<User> ul1 = userMapper.selectByMap(cm);
+        for (User anUl1 : ul1) {
+            print(anUl1);
+        }
+
+        System.err.println("\n------------------selectOne----------------------");
+        User userOne = userMapper.selectOne(new User("abc"));
+        print(userOne);
+
+        System.err.println("\n------------------selectCount----------------------");
+        System.err.println("查询 type=1 总记录数:" + userMapper.selectCount(new EntityWrapper<>(new User(1))));
+        System.err.println("总记录数:" + userMapper.selectCount(null));
+
+        System.err.println("\n------------------selectList-----所有数据----id--DESC--排序----");
+        List<User> ul2 = userMapper.selectList(new EntityWrapper<User>(null, "age,name"));
+        for (User anUl2 : ul2) {
+            print(anUl2);
+        }
+
+        System.err.println("\n------------------list 分页查询 ----查询 testType = 1 的所有数据--id--DESC--排序--------");
+        Page<User> page = new Page<>(1, 2);
+        EntityWrapper<User> ew = new EntityWrapper<>(new User(1));
+
+		/*
+         * 查询字段
+		 */
+        ew.setSqlSelect("age,name");
+
+		/*
+         * 查询条件,SQL 片段(根据常用的写SQL的方式按顺序添加相关条件即可)
+		 */
+        ew.where("name like {0}", "'%dateBatch%'").and("age={0}", 3).orderBy("age,name", true);
+        List<User> paginList = userMapper.selectPage(page, ew);
+        page.setRecords(paginList);
+        for (int i = 0; i < page.getRecords().size(); i++) {
+            print(page.getRecords().get(i));
+        }
+        System.err.println(" 翻页:" + page.toString());
+
+        System.err.println("\n---------------xml---selectListRow 分页查询,不查询总数(此时可自定义 count 查询)----无查询条件--------------");
+        // TODO 查询总数传 Page 对象即可
+        List<User> rowList = userMapper.selectListRow(new Pagination(0, 2, false));
+        for (User aRowList : rowList) {
+            print(aRowList);
+        }
+
+		/*
+         * 用户列表
+		 */
+        System.err.println(" selectList EntityWrapper == null \n");
+        paginList = userMapper.selectList(null);
+        for (User aPaginList : paginList) {
+            print(aPaginList);
+        }
+
+        /**
+         * 自定义方法,删除测试数据
+         */
+        rlt = userMapper.deleteAll();
+        System.err.println("清空测试数据! rlt=" + rlt);
+
+        /**
+         * 提交
+         */
+        session.commit();
+    }
+
+    /*
+     * 打印测试信息
+     */
+    private static void print(User user) {
+        sleep();
+        if (user != null) {
+            System.out.println("\n user: id=" + user.getId() + ", name=" + user.getName() + ", age=" + user.getAge()
+                    + ", testType=" + user.getTestType());
+        } else {
+            System.out.println("\n user is null.");
+        }
+    }
+
+    /*
+     * 慢点打印
+     */
+    private static void sleep() {
+        try {
+            Thread.sleep(1);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 77 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/NotPK.java

@@ -0,0 +1,77 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql.entity;
+
+import java.io.Serializable;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableName;
+
+/**
+ * <p>
+ * 测试实体没有主键依然注入通用方法
+ * </p>
+ *
+ * @author Caratacu
+ * @Date 2016-12-22
+ */
+@TableName("not_pk")
+public class NotPK implements Serializable {
+
+    // 静态属性会自动忽略
+    private static final long serialVersionUID = 1L;
+
+    private String uuid;
+
+    @TableField("is1")
+    private boolean isIs;
+    @TableField("is2")
+    private Boolean isis;
+
+    private String type;
+
+    public Boolean getIsis() {
+        return isis;
+    }
+
+    public void setIsis(Boolean isis) {
+        this.isis = isis;
+    }
+
+    public boolean isIs() {
+        return isIs;
+    }
+
+    public void setIs(boolean is) {
+        isIs = is;
+    }
+
+    public String getUuid() {
+        return uuid;
+    }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+}

+ 86 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/PhoneNumber.java

@@ -0,0 +1,86 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql.entity;
+
+/**
+ * <p>
+ * 测试手机号码
+ * </p>
+ *
+ * @author junyu
+ * @Date 2016-09-09
+ */
+public class PhoneNumber {
+
+    private String countryCode;
+    private String stateCode;
+    private String number;
+
+    public PhoneNumber() {
+    }
+
+    public PhoneNumber(String countryCode, String stateCode, String number) {
+        this.countryCode = countryCode;
+        this.stateCode = stateCode;
+        this.number = number;
+    }
+
+    public PhoneNumber(String string) {
+        if (string != null) {
+            String[] parts = string.split("-");
+            if (parts.length > 0)
+                this.countryCode = parts[0];
+            if (parts.length > 1)
+                this.stateCode = parts[1];
+            if (parts.length > 2)
+                this.number = parts[2];
+        }
+    }
+
+    public String getAsString() {
+        return countryCode + "-" + stateCode + "-" + number;
+
+    }
+
+    public String getCountryCode() {
+        return countryCode;
+    }
+
+    public void setCountryCode(String countryCode) {
+        this.countryCode = countryCode;
+    }
+
+    public String getStateCode() {
+        return stateCode;
+    }
+
+    public void setStateCode(String stateCode) {
+        this.stateCode = stateCode;
+    }
+
+    public String getNumber() {
+        return number;
+    }
+
+    public void setNumber(String number) {
+        this.number = number;
+    }
+
+    @Override
+    public String toString() {
+        return getAsString();
+    }
+}

+ 96 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/Role.java

@@ -0,0 +1,96 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql.entity;
+
+import java.io.Serializable;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableName;
+
+/**
+ * <p>
+ * 测试角色类
+ * </p>
+ *
+ * @author sjy
+ * @Date 2016-09-09
+ */
+@TableName(resultMap = "RoleMap")
+public class Role implements Serializable {
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @TableId
+    private Long id;
+
+    /**
+     * 角色
+     */
+    private String name;
+
+    /**
+     * 排序
+     */
+    private Integer sort;
+
+    /**
+     * 描述
+     */
+    private String description;
+
+    public Long getId() {
+        return this.id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getSort() {
+        return this.sort;
+    }
+
+    public void setSort(Integer sort) {
+        this.sort = sort;
+    }
+
+    public String getDescription() {
+        return this.description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    @Override
+    public String toString() {
+        return "Role{" + "id=" + id + ", name='" + name + '\'' + ", sort=" + sort
+                + ", description='" + description + '\'' + '}';
+    }
+}

+ 91 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/Test.java

@@ -0,0 +1,91 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.activerecord.Model;
+import com.baomidou.mybatisplus.annotations.TableField;
+
+/**
+ * <p>
+ * 测试没有XML同样注入CRUD SQL 实体
+ * </p>
+ *
+ * @author Caratacu
+ * @Date 2016-09-25
+ */
+// 表名为 test 可以不需要注解,特殊如 @TableName("tb_test")
+public class Test extends Model<Test> {
+
+    // 静态属性会自动忽略
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    // 默认会找 id 为主键,特殊命名需要注解 @TableId
+    private Long id;
+
+    private String type;
+
+    @TableField("create_time")
+    private Date createTime;
+
+    public Test() {
+
+    }
+
+    public Test(Long id, String type) {
+        this.id = id;
+        this.type = type;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    @Override
+    protected Serializable pkVal() {
+        return id;
+    }
+
+    public String toString() {
+        return "{id=" + id + ",type=" + type + "}";
+    }
+
+}

+ 209 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/User.java

@@ -0,0 +1,209 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql.entity;
+
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableLogic;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.annotations.Version;
+import com.baomidou.mybatisplus.enums.FieldFill;
+
+/**
+ * <p>
+ * 测试用户类
+ * </p>
+ *
+ * @author hubin sjy
+ * @Date 2016-09-09
+ */
+/* 表名 value 注解【 驼峰命名可无 】, resultMap 注解测试【 映射 xml 的 resultMap 内容 】 */
+@TableName(resultMap = "userMap")
+public class User implements Serializable {
+
+    /* 表字段注解,false 表中不存在的字段,可无该注解 默认 true */
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    /* 主键ID 注解,value 字段名,type 用户输入ID */
+    @TableId(value = "test_id")
+    private Long id;
+
+    /* 测试忽略验证 */
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "test_type", fill = FieldFill.INSERT)
+    @TableLogic(value = "-2") // 该注解为了测试逻辑删除、这里设置 -2 为删除值
+    private Integer testType;
+
+    @TableField(el = "role.id")
+    private Role role;
+
+    private String desc = "默认描述";
+
+    @Version
+    private Integer version;
+
+    // 或@TableField(el = "role,jdbcType=BIGINT)
+    @TableField(el = "phone, typeHandler=com.baomidou.mybatisplus.test.mysql.typehandler.PhoneTypeHandler")
+    private PhoneNumber phone;
+
+    public User() {
+
+    }
+
+    public User(String name) {
+        this.name = name;
+    }
+
+    public User(Integer testType) {
+        this.testType = testType;
+    }
+
+    public User(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public User(Long id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public User(Long id, Integer age) {
+        this.id = id;
+        this.age = age;
+    }
+
+    public User(Long id, String name, Integer age, Integer testType) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+    public User(String name, Integer age, Integer testType) {
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+    /**
+     * 测试类型
+     */
+    public static void main(String args[]) throws IllegalAccessException {
+        User user = new User();
+        user.setName("12306");
+        user.setAge(3);
+        System.err.println(User.class.getName());
+        Field[] fields = user.getClass().getDeclaredFields();
+        for (Field field : fields) {
+            System.out.println("===================================");
+            System.out.println(field.getName());
+            System.out.println(field.getType().toString());
+            field.setAccessible(true);
+            System.out.println(field.get(user));
+        }
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public BigDecimal getPrice() {
+        return price;
+    }
+
+    public void setPrice(BigDecimal price) {
+        this.price = price;
+    }
+
+    public Integer getAge() {
+        return age;
+    }
+
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    public Integer getTestType() {
+        return testType;
+    }
+
+    public void setTestType(Integer testType) {
+        this.testType = testType;
+    }
+
+    public Role getRole() {
+        return role;
+    }
+
+    public void setRole(Role role) {
+        this.role = role;
+    }
+
+    public PhoneNumber getPhone() {
+        return phone;
+    }
+
+    public void setPhone(PhoneNumber phone) {
+        this.phone = phone;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public void setDesc(String desc) {
+        this.desc = desc;
+    }
+
+    public Integer getVersion() {
+        return version;
+    }
+
+    public void setVersion(Integer version) {
+        this.version = version;
+    }
+
+    @Override
+    public String toString() {
+        return "User [id=" + id + ", name=" + name + ", age=" + age + ", price=" + price + ", testType=" + testType
+                + ", role=" + role + ", desc=" + desc + ", phone=" + phone + "]";
+    }
+}

+ 31 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/NotPKMapper.java

@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql.mapper;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.mysql.entity.NotPK;
+
+/**
+ * <p>
+ * 继承 BaseMapper,就自动拥有CRUD方法
+ * </p>
+ *
+ * @author Caratacus
+ * @Date 2016-12-22
+ */
+public interface NotPKMapper extends BaseMapper<NotPK> {
+
+}

+ 12 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/RoleMapper.java

@@ -0,0 +1,12 @@
+package com.baomidou.mybatisplus.test.mysql.mapper;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.mysql.entity.Role;
+
+/**
+ * @author junyu
+ * @Date 2016-09-09
+ */
+public interface RoleMapper extends BaseMapper<Role> {
+
+}

+ 39 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/TestMapper.java

@@ -0,0 +1,39 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql.mapper;
+
+import org.apache.ibatis.annotations.Insert;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.mysql.entity.Test;
+
+/**
+ * <p>
+ * 继承 BaseMapper,就自动拥有CRUD方法
+ * </p>
+ *
+ * @author Caratacus hubin
+ * @Date 2016-09-25
+ */
+public interface TestMapper extends BaseMapper<Test> {
+
+    /**
+     * 注解插入【测试】
+     */
+    @Insert("insert into test(id,type) values(#{id},#{type})")
+    int insertInjector(Test test);
+
+}

+ 74 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/UserMapper.java

@@ -0,0 +1,74 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql.mapper;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.RowBounds;
+
+import com.baomidou.mybatisplus.test.mysql.MyBaseMapper;
+import com.baomidou.mybatisplus.test.mysql.entity.Role;
+import com.baomidou.mybatisplus.test.mysql.entity.User;
+
+/**
+ * <p>
+ * 继承 BaseMapper,就自动拥有CRUD方法
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-01-23
+ */
+public interface UserMapper extends MyBaseMapper<User> {
+
+    /**
+     * 用户列表,分页显示
+     *
+     * @param pagination 传递参数包含该属性,即自动分页
+     * @return
+     */
+    List<User> selectListRow(RowBounds pagination);
+
+    /**
+     * 注解插入【测试】
+     */
+    @Insert("insert into user(test_id,name,age) values(#{id},#{name},#{age})")
+    int insertInjector(User user);
+
+    /**
+     * 自定义注入方法
+     */
+    int deleteAll();
+
+    /**
+     * 自定义注入逻辑删除方法<br>
+     * com.baomidou.mybatisplus.test.mysql.MetaObjectHandlerTest
+     */
+    int deleteLogicById(@Param("id") Long id);
+
+    /**
+     * 根据主键批量查询
+     *
+     * @param pagination
+     * @param ids
+     * @return
+     */
+    List<User> forSelect(RowBounds pagination, @Param("ids") List<String> ids);
+
+    // 测试跨 xml resultMap
+    List<Role> selectRoleList();
+}

+ 33 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/service/IUserService.java

@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql.service;
+
+import com.baomidou.mybatisplus.service.IService;
+import com.baomidou.mybatisplus.test.mysql.entity.User;
+
+/**
+ * <p>
+ * Service层测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-01-30
+ */
+public interface IUserService extends IService<User> {
+
+    void testSqlInjector();
+
+}

+ 47 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/service/impl/UserServiceImpl.java

@@ -0,0 +1,47 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql.service.impl;
+
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.test.mysql.entity.User;
+import com.baomidou.mybatisplus.test.mysql.mapper.UserMapper;
+import com.baomidou.mybatisplus.test.mysql.service.IUserService;
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+
+/**
+ * <p>
+ * Service层测试
+ * </p>
+ *
+ * @author hubin
+ * @date 2017-01-30
+ */
+@Service
+public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
+
+    // 注入测试
+    public void testSqlInjector() {
+        Long id = IdWorker.getId();
+        int rlt = baseMapper.insert(new User(id, "abc", 18, 1));
+        System.err.println("插入ID:" + id + ", 执行结果:" + rlt);
+        rlt = baseMapper.deleteLogicById(id);
+        System.err.println("测试注入执行结果:" + rlt);
+        System.err.println("逻辑修改:" + baseMapper.selectById(id).toString());
+    }
+
+}

+ 63 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/typehandler/PhoneTypeHandler.java

@@ -0,0 +1,63 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.mysql.typehandler;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedJdbcTypes;
+import org.apache.ibatis.type.MappedTypes;
+
+import com.baomidou.mybatisplus.test.mysql.entity.PhoneNumber;
+
+/**
+ * <p>
+ * 自定义测试 TypeHandler
+ * </p>
+ *
+ * @author junyu
+ * @Date 2016-09-09
+ */
+@MappedTypes(PhoneNumber.class)
+@MappedJdbcTypes(JdbcType.VARCHAR)
+public class PhoneTypeHandler extends BaseTypeHandler<PhoneNumber> {
+
+    @Override
+    public void setNonNullParameter(PreparedStatement ps, int i, PhoneNumber parameter, JdbcType jdbcType)
+            throws SQLException {
+        System.err.println("--------- Executing PhoneTypeHandler --------- ");
+        ps.setString(i, parameter.getAsString());
+    }
+
+    @Override
+    public PhoneNumber getNullableResult(ResultSet rs, String columnName) throws SQLException {
+        return new PhoneNumber(rs.getString(columnName));
+    }
+
+    @Override
+    public PhoneNumber getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
+        return new PhoneNumber(rs.getString(columnIndex));
+    }
+
+    @Override
+    public PhoneNumber getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
+        return new PhoneNumber(cs.getString(columnIndex));
+    }
+}

+ 62 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/oracle/OracleDruidTest.java

@@ -0,0 +1,62 @@
+package com.baomidou.mybatisplus.test.oracle;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.test.oracle.config.DruidOracleDBConfig;
+import com.baomidou.mybatisplus.test.oracle.config.OracleMybatisPlusConfig;
+import com.baomidou.mybatisplus.test.oracle.entity.TestSequser;
+import com.baomidou.mybatisplus.test.oracle.mapper.TestSequserMapper;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/7/4
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {DruidOracleDBConfig.class, OracleMybatisPlusConfig.class})
+public class OracleDruidTest {
+
+    @Autowired
+    TestSequserMapper sequserMapper;
+
+    @Test
+    public void testSelectListMp() {
+        List<TestSequser> list = sequserMapper.selectList(new EntityWrapper<TestSequser>());
+        for (TestSequser u : list) {
+            System.out.println(u);
+        }
+    }
+
+    @Test
+    public void testSelectListNative() {
+        List<TestSequser> list = sequserMapper.getList();
+        for (TestSequser u : list) {
+            System.out.println(u);
+        }
+    }
+
+    @Test
+    public void testInsert() {
+        TestSequser user = new TestSequser();
+        user.setName("seqtest0627");
+        user.setAge(12);
+        user.setTestType(1);
+        sequserMapper.insert(user);
+        Long id = user.getId();
+        Assert.assertNotNull(id);
+
+
+    }
+
+
+}

+ 62 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/oracle/OracleUserTest.java

@@ -0,0 +1,62 @@
+package com.baomidou.mybatisplus.test.oracle;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.test.oracle.config.OracleDBConfig;
+import com.baomidou.mybatisplus.test.oracle.config.OracleMybatisPlusConfig;
+import com.baomidou.mybatisplus.test.oracle.entity.TestSequser;
+import com.baomidou.mybatisplus.test.oracle.mapper.TestSequserMapper;
+
+/**
+ * <p>
+ * oracle user test for spring
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/6/14
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {OracleDBConfig.class, OracleMybatisPlusConfig.class})
+public class OracleUserTest {
+
+    @Autowired
+    TestSequserMapper sequserMapper;
+
+    @Test
+    public void testSelectListMp() {
+        List<TestSequser> list = sequserMapper.selectList(new EntityWrapper<TestSequser>());
+        for (TestSequser u : list) {
+            System.out.println(u);
+        }
+    }
+
+    @Test
+    public void testSelectListNative() {
+        List<TestSequser> list = sequserMapper.getList();
+        for (TestSequser u : list) {
+            System.out.println(u);
+        }
+    }
+
+    @Test
+    public void testInsert() {
+        TestSequser user = new TestSequser();
+        user.setName("seqtest0627");
+        user.setAge(12);
+        user.setTestType(1);
+        sequserMapper.insert(user);
+        Long id = user.getId();
+        Assert.assertNotNull(id);
+
+
+    }
+
+}

+ 115 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/oracle/TestSequserMapperTest.java

@@ -0,0 +1,115 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.oracle;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+
+import com.baomidou.mybatisplus.MybatisSessionFactoryBuilder;
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.incrementer.OracleKeyGenerator;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.test.oracle.entity.TestSequser;
+import com.baomidou.mybatisplus.test.oracle.mapper.TestSequserMapper;
+
+
+/**
+ * <p>
+ * oracle sequence 测试类
+ * </p>
+ *
+ * @author zashitou
+ * @Date 2017-04-20
+ */
+public class TestSequserMapperTest {
+
+
+    /**
+     * Test Oracle Sequence
+     */
+    public static void main(String[] args) {
+
+        //加载配置文件
+        InputStream in = TestSequserMapperTest.class.getClassLoader().getResourceAsStream("oracle-config.xml");
+
+        MybatisSessionFactoryBuilder mf = new MybatisSessionFactoryBuilder();
+
+        /** 设置数据库类型为 oracle */
+        GlobalConfiguration gc = new GlobalConfiguration();
+        gc.setDbType("oracle");
+        gc.setDbColumnUnderline(true);
+        gc.setKeyGenerator(new OracleKeyGenerator());
+        mf.setGlobalConfig(gc);
+        SqlSessionFactory sessionFactory = mf.build(in);
+        SqlSession session = sessionFactory.openSession();
+        TestSequserMapper testSequserMapper = session.getMapper(TestSequserMapper.class);
+        /**
+         * 插入
+         */
+        TestSequser one = new TestSequser("abc", 18, 1);
+        int rlt = testSequserMapper.insert(one);
+        System.err.println("\n one.id-------:" + one.getId());
+//        sleep();
+
+        /**
+         * 批量插入
+         */
+        List<TestSequser> ul = new ArrayList<>();
+        ul.add(new TestSequser("abc2", 18, 2));
+        ul.add(new TestSequser("abc3", 18, 3));
+        ul.add(new TestSequser("abc4", 18, 4));
+        ul.add(new TestSequser("abc5", 18, 5));
+        ul.add(new TestSequser("abc6", 18, 6));
+        for (TestSequser u : ul) {
+            rlt = testSequserMapper.insert(u);
+        }
+//        for (TestSequser u : ul) {
+//            System.err.println("\n one.id-------:" + u.getId());
+//        }
+
+        System.out.println("********************");
+        List<TestSequser> testList = testSequserMapper.getList();
+        for (TestSequser u : testList) {
+            System.out.println(u);
+        }
+
+        testList = testSequserMapper.selectList(new EntityWrapper<TestSequser>());
+        for (TestSequser u : testList) {
+            System.out.println(u);
+        }
+
+        /**
+         * 提交
+         */
+        session.commit();
+    }
+
+
+    /*
+     * 慢点打印
+     */
+    private static void sleep() {
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 157 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/oracle/TestUserMapperTest.java

@@ -0,0 +1,157 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.baomidou.mybatisplus.test.oracle;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+
+import com.baomidou.mybatisplus.MybatisSessionFactoryBuilder;
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.test.oracle.entity.TestUser;
+import com.baomidou.mybatisplus.test.oracle.mapper.TestUserMapper;
+
+/**
+ * <p>
+ * MybatisPlus 测试类
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-04-25
+ */
+public class TestUserMapperTest {
+
+
+    /**
+     * RUN 测试( 更多查看 MySql 测试类 )
+     */
+    public static void main(String[] args) {
+
+        //加载配置文件
+        InputStream in = TestUserMapperTest.class.getClassLoader().getResourceAsStream("oracle-config.xml");
+
+		/*
+         * 此处采用 MybatisSessionFactoryBuilder 构建
+		 * SqlSessionFactory,目的是引入BaseMapper功能
+		 */
+        MybatisSessionFactoryBuilder mf = new MybatisSessionFactoryBuilder();
+
+        /** 设置数据库类型为 oracle */
+        GlobalConfiguration gc = new GlobalConfiguration();
+        gc.setDbType("oracle");
+        mf.setGlobalConfig(gc);
+
+		/*
+         * 1、数据库字段驼峰命名不需要任何设置
+		 * 2、当前演示是驼峰下划线混合命名
+		 * 3、如下开启,表示数据库字段使用下划线命名,该设置是全局的。
+		 *	 开启该设置实体可无 @TableId(value = "test_id") 字段映射
+		 */
+        //mf.setDbColumnUnderline(true);
+
+        SqlSessionFactory sessionFactory = mf.build(in);
+        SqlSession session = sessionFactory.openSession();
+        TestUserMapper testUserMapper = session.getMapper(TestUserMapper.class);
+        System.err.println(" debug run 查询执行 test_user 表数据变化! ");
+        session.delete("deleteAll");
+
+        /**
+         * 插入
+         */
+        int rlt = testUserMapper.insert(new TestUser("10", "abc", 18, 1));
+        System.err.println("\n--------------insert-------" + rlt);
+        sleep();
+
+        /**
+         * 批量插入
+         */
+        List<TestUser> ul = new ArrayList<>();
+        ul.add(new TestUser("11", "1a", 11, 1));
+        ul.add(new TestUser("12", "2a", 12, 2));
+        ul.add(new TestUser("a", 1, 1));
+        ul.add(new TestUser("b", 2, 2));
+        ul.add(new TestUser("c", 3, 1));
+        for (TestUser u : ul) {
+            rlt = testUserMapper.insert(u);
+        }
+        System.err.println("\n--------------insertBatch-------" + rlt);
+        sleep();
+
+        /**
+         * 批量更新
+         */
+        List<TestUser> ul1 = new ArrayList<>();
+        ul1.add(new TestUser("10", "update-0a", 11, 1));
+        ul1.add(new TestUser("11", "update-1a", 11, 1));
+        ul1.add(new TestUser("12", "update-2a", 12, 2));
+        for (TestUser u : ul1) {
+            rlt = testUserMapper.updateById(u);
+        }
+        System.err.println("\n--------------updateBatchById-------" + rlt);
+        sleep();
+
+        System.err.println("\n------------------list 分页查询 ----查询 testType = 1 的所有数据--id--DESC--排序--------");
+        Page<TestUser> page = new Page<>(1, 2);
+        EntityWrapper<TestUser> ew = new EntityWrapper<>(new TestUser(1), "TEST_ID DESC");
+        List<TestUser> paginList = testUserMapper.selectPage(page, ew);
+        page.setRecords(paginList);
+        for (int i = 0; i < page.getRecords().size(); i++) {
+            print(page.getRecords().get(i));
+        }
+        System.err.println(" 翻页:" + page.toString());
+
+		/* 删除测试数据  */
+        rlt = session.delete("deleteAll");
+        System.err.println("清空测试数据! rlt=" + rlt);
+
+        /**
+         * 提交
+         */
+        session.commit();
+    }
+
+
+    /*
+     * 打印测试信息
+     */
+    private static void print(TestUser user) {
+        sleep();
+        if (user != null) {
+            System.out.println("\n user: id="
+                    + user.getTestId() + ", name=" + user.getName() + ", age=" + user.getAge() + ", testType="
+                    + user.getTestType());
+        } else {
+            System.out.println("\n user is null.");
+        }
+    }
+
+
+    /*
+     * 慢点打印
+     */
+    private static void sleep() {
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 36 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/oracle/config/DruidOracleDBConfig.java

@@ -0,0 +1,36 @@
+package com.baomidou.mybatisplus.test.oracle.config;
+
+import javax.sql.DataSource;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import com.zaxxer.hikari.HikariDataSource;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2017/7/4
+ */
+@Configuration
+@EnableTransactionManagement
+public class DruidOracleDBConfig {
+
+    @Bean
+    public DataSource getDruidDataSource() {
+        HikariDataSource dataSource = new HikariDataSource();
+        dataSource.setJdbcUrl("jdbc:oracle:thin:@192.168.10.169:1521:orcl");
+        dataSource.setUsername("sa");
+        dataSource.setPassword("sa");
+        return dataSource;
+    }
+
+    @Bean
+    public DataSourceTransactionManager transactionManager(DataSource ds) {
+        return new DataSourceTransactionManager(ds);
+    }
+}

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott