diff --git a/docs/zh/intro/getting-started.md b/docs/zh/intro/getting-started.md index 648dc77d..506cdec6 100644 --- a/docs/zh/intro/getting-started.md +++ b/docs/zh/intro/getting-started.md @@ -29,8 +29,18 @@ Maven示例: mybatis-flex-core 1.2.0 + + com.mybatis-flex + mybatis-flex-processor + 1.2.0 + provided + ``` +> 如果配置了annotationProcessorPaths,此处可以省略mybatis-flex-processor的依赖 +> +> 参考:[APT 设置章节](../others/apt.md) + Gradle示例: ```groovy diff --git a/docs/zh/intro/maven.md b/docs/zh/intro/maven.md index 4007f2f2..a5ac52b7 100644 --- a/docs/zh/intro/maven.md +++ b/docs/zh/intro/maven.md @@ -1,6 +1,9 @@ # Maven 依赖 > 以下的 xml maven 依赖示例中,可能并非最新的 Mybatis-Flex 版本,请自行查看最新版本,并修改版本号。 +> +> 建议配置 annotationProcessorPaths,那么可以省略mybatis-flex-processor的依赖 +> 1、只用到了 Mybatis,没用到 Spring 的场景: @@ -11,6 +14,12 @@ mybatis-flex-core 1.2.0 + + com.mybatis-flex + mybatis-flex-processor + 1.2.0 + provided + ``` 2、用到了 Spring 的场景 @@ -21,6 +30,12 @@ mybatis-flex-spring 1.2.0 + + com.mybatis-flex + mybatis-flex-processor + 1.2.0 + provided + `````` 3、用到了 Spring Boot 的场景 @@ -31,4 +46,34 @@ mybatis-flex-spring-boot-starter 1.2.0 -``` \ No newline at end of file + + com.mybatis-flex + mybatis-flex-processor + 1.2.0 + provided + +``` + +4. 配置 annotationProcessor + + `mybatis-flex-processor`提供APT服务,可以配置到annotationProcessorPaths,配置后,无需在依赖中声明`mybatis-flex-processor`依赖。 + + 参考:[APT 设置-和 Lombok、Mapstruct 整合](../others/apt.md) + +```xml + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + + com.mybatis-flex + mybatis-flex-processor + 1.2.0 + + + + +``` + diff --git a/docs/zh/others/apt.md b/docs/zh/others/apt.md index 5e3d2186..f9b245b6 100644 --- a/docs/zh/others/apt.md +++ b/docs/zh/others/apt.md @@ -5,6 +5,25 @@ Mybatis-Flex 使用了 APT(Annotation Processing Tool)技术,在项目编 ![](../../assets/images/build_idea.png) +> 从1.1.9版本开始,APT默认不生成 Mapper 类文件。如需开启,参考下方配置选项。 + +## 配置文件和选项 + +要对Mybatis-Flex 的APT细节选项进行配置,你需要在`resources`目录下创建名为`mybatis-flex.properties`的文件。 + +支持的配置选项如下: + +| 属性名 | 含义 | 约束 | 默认值 | +| ------------------------------- | ------------------------ | -------------------------------------------------------- | ------------------------------------ | +| processor.enable | 全局启用apt开关 | true/false | true | +| processor.mappersGenerateEnable | 开启 Mapper 自动生成 | true/false | false | +| processor.genPath | APT 代码生成路径 | 合法的绝对或相对路径 | target/generated-sources/annotations | +| processor.tablesPackage | Tables 类名 | 合法的包名 | ${entityPackage}.table | +| processor.tablesClassName | Tables 类名 | 合法的类名 | Tables | +| processor.baseMapperClass | 自定义 Mapper 的父类 | 全路径类名 | com.mybatisflex.core.BaseMapper | +| processor.mappersPackage | 自定义 Mapper 生成的包名 | 合法的包名 | ${entityPackage}.mapper | +| processor.tablesNameStyle | 生成辅助类的字段风格 | upperCase, lowerCase
upperCamelCase, lowerCamelCase | upperCase | +| processor.entity.ignoreSuffixes | 过滤 Entity 后缀 | string | - | @@ -144,7 +163,7 @@ processor.baseMapperClass=com.domain.mapper.MyBaseMapper com.mybatis-flex - mybatis-flex-annotation + mybatis-flex-processor ${mybatis-flex.version} @@ -159,7 +178,7 @@ processor.baseMapperClass=com.domain.mapper.MyBaseMapper ``` dependencies { ... - annotationProcessor 'com.mybatis-flex:mybatis-flex-annotation:1.2.0' + annotationProcessor 'com.mybatis-flex:mybatis-flex-processor:1.2.0' } ``` @@ -172,4 +191,3 @@ dependencies { ![](../../assets/images/apt_idea.png) - diff --git a/mybatis-flex-annotation/pom.xml b/mybatis-flex-annotation/pom.xml index 763192d6..31805c48 100644 --- a/mybatis-flex-annotation/pom.xml +++ b/mybatis-flex-annotation/pom.xml @@ -16,42 +16,4 @@ mybatis - - - - 8 - 8 - - - - - - src/main/resources - - **/* - - - - *.properties - - - - - target/generated-sources - - - - - - maven-compiler-plugin - 3.8.1 - - none - 1.8 - 1.8 - - - - - \ No newline at end of file diff --git a/mybatis-flex-processor/pom.xml b/mybatis-flex-processor/pom.xml new file mode 100644 index 00000000..37284040 --- /dev/null +++ b/mybatis-flex-processor/pom.xml @@ -0,0 +1,62 @@ + + + + parent + com.mybatis-flex + 1.2.0 + + 4.0.0 + + mybatis-flex-processor + + + org.mybatis + mybatis + + + com.mybatis-flex + mybatis-flex-annotation + 1.2.0 + + + + + + 8 + 8 + + + + + + src/main/resources + + **/* + + + + *.properties + + + + + target/generated-sources + + + + + + maven-compiler-plugin + 3.8.1 + + none + 1.8 + 1.8 + + + + + + \ No newline at end of file diff --git a/mybatis-flex-annotation/src/main/java/com/mybatisflex/processor/MyBatisFlexProps.java b/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/MyBatisFlexProps.java similarity index 100% rename from mybatis-flex-annotation/src/main/java/com/mybatisflex/processor/MyBatisFlexProps.java rename to mybatis-flex-processor/src/main/java/com/mybatisflex/processor/MyBatisFlexProps.java diff --git a/mybatis-flex-annotation/src/main/java/com/mybatisflex/processor/QueryEntityProcessor.java b/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/QueryEntityProcessor.java similarity index 99% rename from mybatis-flex-annotation/src/main/java/com/mybatisflex/processor/QueryEntityProcessor.java rename to mybatis-flex-processor/src/main/java/com/mybatisflex/processor/QueryEntityProcessor.java index 48904c38..521c5fb9 100644 --- a/mybatis-flex-annotation/src/main/java/com/mybatisflex/processor/QueryEntityProcessor.java +++ b/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/QueryEntityProcessor.java @@ -30,7 +30,8 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Types; -import javax.tools.*; +import javax.tools.Diagnostic; +import javax.tools.JavaFileObject; import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; @@ -116,7 +117,7 @@ public class QueryEntityProcessor extends AbstractProcessor { public boolean process(Set annotations, RoundEnvironment roundEnv) { if (!roundEnv.processingOver()) { - + System.out.println("mybatis flex processor run start..."); MyBatisFlexProps props = new MyBatisFlexProps(filer); String enable = props.getProperties().getProperty("processor.enable", ""); diff --git a/mybatis-flex-annotation/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/mybatis-flex-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor similarity index 100% rename from mybatis-flex-annotation/src/main/resources/META-INF/services/javax.annotation.processing.Processor rename to mybatis-flex-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor diff --git a/mybatis-flex-test/mybatis-flex-native-test/pom.xml b/mybatis-flex-test/mybatis-flex-native-test/pom.xml index 72b6dd24..ee0adee1 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/pom.xml +++ b/mybatis-flex-test/mybatis-flex-native-test/pom.xml @@ -95,48 +95,4 @@ - - - - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - - - - - - - - - - - - - - - - com.mybatis-flex - mybatis-flex-annotation - 1.2.0 - - - - - - - \ No newline at end of file diff --git a/mybatis-flex-test/pom.xml b/mybatis-flex-test/pom.xml index f0f8b0f9..c725d916 100644 --- a/mybatis-flex-test/pom.xml +++ b/mybatis-flex-test/pom.xml @@ -11,7 +11,7 @@ mybatis-flex-test pom - + mybatis-flex-native-test mybatis-flex-spring-test @@ -23,4 +23,47 @@ 8 + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + + + + + + + + + + + + + com.mybatis-flex + mybatis-flex-processor + 1.2.0 + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index a8ce5988..65ab1d4f 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,7 @@ mybatis-flex-spring-boot-starter mybatis-flex-solon-plugin mybatis-flex-test + mybatis-flex-processor