瀏覽代碼

starter增加默认xml路径扫描.

聂秋秋 6 年之前
父節點
當前提交
97f619918c

+ 3 - 4
build.gradle

@@ -171,15 +171,14 @@ subprojects {
         exclude("**/mysql/**")
     }
 
-    //noinspection GroovyAssignabilityCheck
     task javadocJar(type: Jar) {
         archiveClassifier = 'javadoc'
         from javadoc
     }
 
-    tasks.whenTaskAdded {
-        if (this.name.contains("signMavenJavaPublication")) {
-            this.enabled = File(project.property("signing.secretKeyRingFile") as String).isFile
+    tasks.whenTaskAdded { task ->
+        if (task.name.contains('signMavenJavaPublication')) {
+            task.enabled = new File(project.property('signing.secretKeyRingFile') as String).isFile()
         }
     }
 

+ 2 - 1
mybatis-plus-boot-starter/src/main/java/com/baomidou/mybatisplus/autoconfigure/MybatisPlusProperties.java

@@ -52,8 +52,9 @@ public class MybatisPlusProperties {
 
     /**
      * Locations of MyBatis mapper files.
+     * @since 3.1.2 add default value
      */
-    private String[] mapperLocations;
+    private String[] mapperLocations = new String[]{"classpath*:/mapper/**/*.xml"};
 
     /**
      * Packages to search type aliases. (Package delimiters are ",; \t\n")

+ 1 - 1
mybatis-plus-boot-starter/src/test/java/com/baomidou/mybatisplus/starter/MetadataTest.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2019, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, baomidou (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

+ 40 - 0
mybatis-plus-boot-starter/src/test/java/com/baomidou/mybatisplus/starter/MybatisPlusPropertiesTest.java

@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (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>
+ * https://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.starter;
+
+import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * 属性测试
+ *
+ * @author nieqiurong 2019/5/4.
+ */
+class MybatisPlusPropertiesTest {
+    
+    @Test
+    void resolveMapperLocationsTest() {
+        MybatisPlusProperties mybatisPlusProperties = new MybatisPlusProperties();
+        //默认扫描 classpath*:/mapper/**/*.xml
+        Assertions.assertEquals(mybatisPlusProperties.getMapperLocations()[0], "classpath*:/mapper/**/*.xml");
+        Assertions.assertEquals(2, mybatisPlusProperties.resolveMapperLocations().length);
+        //扫描不存在的路径
+        mybatisPlusProperties.setMapperLocations(new String[]{"classpath:mybatis-plus/*.xml"});
+        Assertions.assertEquals(mybatisPlusProperties.resolveMapperLocations().length, 0);
+    }
+    
+}

+ 30 - 0
mybatis-plus-boot-starter/src/test/java/com/baomidou/mybatisplus/starter/entity/Test.java

@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (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>
+ * https://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.starter.entity;
+
+import lombok.Data;
+
+/**
+ * @author nieqiurong 2019/5/4.
+ */
+@Data
+public class Test {
+    
+    private Long id;
+    
+    private String name;
+    
+}

+ 26 - 0
mybatis-plus-boot-starter/src/test/java/com/baomidou/mybatisplus/starter/mapper/TestMapper.java

@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (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>
+ * https://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.starter.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.starter.entity.Test;
+
+/**
+ * @author nieqiurong 2019/5/4.
+ */
+public interface TestMapper extends BaseMapper<Test> {
+
+}

+ 1 - 1
mybatis-plus-boot-starter/src/test/java/com/baomidou/mybatisplus/starter/pom/GeneratePomTest.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2019, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, baomidou (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

+ 5 - 0
mybatis-plus-boot-starter/src/test/resources/mapper/modulea/testa.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.baomidou.mybatisplus.starter.mapper.TestMapper">
+
+</mapper>

+ 5 - 0
mybatis-plus-boot-starter/src/test/resources/mapper/moduleb/testb.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.baomidou.mybatisplus.starter.mapper.TestMapper">
+
+</mapper>