Explorar el Código

Merge branch '3.0' of https://github.com/baomidou/mybatis-plus into github3.0

hubin hace 3 años
padre
commit
7f368fe651

+ 4 - 4
build.gradle

@@ -13,7 +13,7 @@ ext {
     libraries = [
         mybatisVersion = '3.5.9',
         mybatisSpringVersion = '2.0.6',
-        mybatisSpringBootStarterVersion = '2.2.0',
+        mybatisSpringBootStarterVersion = '2.2.1',
         springVersion = '5.3.9',
         springBootVersion = '2.5.3',
         jsqlparserVersion = '4.3',
@@ -47,7 +47,7 @@ ext {
         "mybatis-spring-boot-starter": "org.mybatis.spring.boot:mybatis-spring-boot-starter:${mybatisSpringBootStarterVersion}",
         //test
         "spring-test"                : "org.springframework:spring-test:${springVersion}",
-        "assertj-core"               : "org.assertj:assertj-core:3.19.0",
+        "assertj-core"               : "org.assertj:assertj-core:3.22.0",
         "junit-jupiter"              : "org.junit.jupiter:junit-jupiter:${junitVersion}",
         "fastjson"                   : "com.alibaba:fastjson:1.2.76",
         "jackson"                    : "com.fasterxml.jackson.core:jackson-databind:2.12.5",
@@ -60,10 +60,10 @@ ext {
         "oracle"                     : fileTree(dir: 'libs', includes: ['ojdbc-11.2.0.3-jdk16.jar']),
         "dm"                         : fileTree(dir: 'libs', includes: ["jdbcDriver-18.jar"]),
         "kingbase"                   : fileTree(dir: 'libs', includes: ["kingbase8-8.2.0.jar"]),
-        "h2"                         : "com.h2database:h2:1.4.200",
+        "h2"                         : "com.h2database:h2:2.0.206",
         "mysql"                      : "mysql:mysql-connector-java:8.0.26",
         "sqlite"                     : "org.xerial:sqlite-jdbc:3.36.0.3",
-        "firebird"                   : "org.firebirdsql.jdbc:jaybird:4.0.4.java8",
+        "firebird"                   : "org.firebirdsql.jdbc:jaybird:4.0.5.java8",
         //cache
         "mybatis-ehcache"            : "org.mybatis.caches:mybatis-ehcache:1.2.1",
         "mybatis-redis"              : "org.mybatis.caches:mybatis-redis:1.0.0-beta2",

+ 3 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfo.java

@@ -28,6 +28,7 @@ import org.apache.ibatis.mapping.ResultFlag;
 import org.apache.ibatis.mapping.ResultMap;
 import org.apache.ibatis.mapping.ResultMapping;
 import org.apache.ibatis.reflection.Reflector;
+import org.apache.ibatis.reflection.SystemMetaObject;
 import org.apache.ibatis.session.Configuration;
 
 import java.lang.reflect.Constructor;
@@ -46,7 +47,6 @@ import static java.util.stream.Collectors.joining;
 @Data
 @Setter(AccessLevel.PACKAGE)
 @Accessors(chain = true)
-@SuppressWarnings("serial")
 public class TableInfo implements Constants {
 
     /**
@@ -189,6 +189,7 @@ public class TableInfo implements Constants {
     @Deprecated
     public TableInfo(Class<?> entityType) {
         this.entityType = entityType;
+        this.reflector = SystemMetaObject.NULL_META_OBJECT.getReflectorFactory().findForClass(entityType);
     }
 
     /**
@@ -224,6 +225,7 @@ public class TableInfo implements Constants {
         Assert.notNull(configuration, "Error: You need Initialize MybatisConfiguration !");
         this.configuration = configuration;
         this.underCamel = configuration.isMapUnderscoreToCamelCase();
+        this.reflector = configuration.getReflectorFactory().findForClass(this.entityType);
     }
 
     /**

+ 39 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/metadata/TableInfoTest.java

@@ -0,0 +1,39 @@
+package com.baomidou.mybatisplus.core.metadata;
+
+import org.apache.ibatis.session.Configuration;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author nieiqurong
+ */
+public class TableInfoTest {
+
+    static class Demo {
+
+        String name;
+
+    }
+
+    @Test
+    void testCreate() {
+        TableInfo tableInfo;
+        Configuration configuration = new Configuration();
+        configuration.setMapUnderscoreToCamelCase(true);
+        tableInfo = new TableInfo(Demo.class);
+        Demo demo = tableInfo.newInstance();
+        tableInfo.setPropertyValue(demo, "name", "test");
+        assertThat(tableInfo.getPropertyValue(demo, "name")).isEqualTo("test");
+        assertThat(tableInfo.isUnderCamel()).isFalse();
+        assertThat(tableInfo.getReflector()).isNotNull();
+        tableInfo.setConfiguration(configuration);
+        assertThat(tableInfo.isUnderCamel()).isTrue();
+        assertThat(tableInfo.getReflector()).isNotNull();
+        tableInfo = new TableInfo(configuration, Object.class);
+        assertThat(tableInfo.isUnderCamel()).isTrue();
+        assertThat(tableInfo.getReflector()).isNotNull();
+    }
+
+
+}