From 93d1ceb6d17da4758e81aa584e613af347d1bacf Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 5 Jul 2023 22:44:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20@Mapper=20=E6=B3=A8=E8=A7=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisflex/codegen/config/MapperConfig.java | 14 ++++++++++++++ .../src/main/resources/templates/enjoy/mapper.tpl | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/MapperConfig.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/MapperConfig.java index 62fc4905..b85cc977 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/MapperConfig.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/MapperConfig.java @@ -46,6 +46,11 @@ public class MapperConfig { */ private boolean overwriteEnable; + /** + * 是否添加 {@code @Mapper} 注解。 + */ + private boolean mapperAnnotation; + public String buildSuperClassImport() { return supperClass.getName(); } @@ -114,4 +119,13 @@ public class MapperConfig { return this; } + public boolean isMapperAnnotation() { + return mapperAnnotation; + } + + public MapperConfig setMapperAnnotation(boolean mapperAnnotation) { + this.mapperAnnotation = mapperAnnotation; + return this; + } + } \ No newline at end of file diff --git a/mybatis-flex-codegen/src/main/resources/templates/enjoy/mapper.tpl b/mybatis-flex-codegen/src/main/resources/templates/enjoy/mapper.tpl index 24040c98..32670d19 100644 --- a/mybatis-flex-codegen/src/main/resources/templates/enjoy/mapper.tpl +++ b/mybatis-flex-codegen/src/main/resources/templates/enjoy/mapper.tpl @@ -1,5 +1,8 @@ package #(packageConfig.mapperPackage); +#if(mapperConfig.isMapperAnnotation()) +import org.apache.ibatis.annotations.Mapper; +#end import #(mapperConfig.buildSuperClassImport()); import #(packageConfig.entityPackage).#(table.buildEntityClassName()); @@ -9,6 +12,9 @@ import #(packageConfig.entityPackage).#(table.buildEntityClassName()); * @author #(javadocConfig.getAuthor()) * @since #(javadocConfig.getSince()) */ +#if(mapperConfig.isMapperAnnotation()) +@Mapper +#end public interface #(table.buildMapperClassName()) extends #(mapperConfig.buildSuperClassName())<#(table.buildEntityClassName())> { }