From 2127e1ba5f13af6f56bc2360c6f0afdcda9fb63f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Mon, 3 Apr 2023 16:46:29 +0800 Subject: [PATCH] optimize QueryEntityProcesser.java --- .../processer/QueryEntityProcesser.java | 24 +++++++++++++++---- .../test/mapper/AccountMapper.java | 24 ------------------- .../test/mapper/AccountMapper.java | 22 ----------------- 3 files changed, 19 insertions(+), 51 deletions(-) delete mode 100644 mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java delete mode 100644 mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java diff --git a/mybatis-flex-annotation/src/main/java/com/mybatisflex/processer/QueryEntityProcesser.java b/mybatis-flex-annotation/src/main/java/com/mybatisflex/processer/QueryEntityProcesser.java index 593fed36..7179e460 100644 --- a/mybatis-flex-annotation/src/main/java/com/mybatisflex/processer/QueryEntityProcesser.java +++ b/mybatis-flex-annotation/src/main/java/com/mybatisflex/processer/QueryEntityProcesser.java @@ -202,7 +202,7 @@ public class QueryEntityProcesser extends AbstractProcessor { //是否开启 mapper 生成功能 if ("true".equalsIgnoreCase(mappersGenerateEnable)) { String realMapperPackage = genMappersPackage == null || genMappersPackage.trim().length() == 0 - ? guessPackage.substring(0, guessPackage.length() - 5) + "mapper" : genMappersPackage; + ? guessMapperPackage(entityClassElement.toString()) : genMappersPackage; genMapperClass(genPath, realMapperPackage, entityClassElement.toString()); } }); @@ -218,6 +218,20 @@ public class QueryEntityProcesser extends AbstractProcessor { } + private static String guessMapperPackage(String entityClassName) { + if (!entityClassName.contains(".")) { + return "mapper"; + } else { + String entityPackage = entityClassName.substring(0, entityClassName.lastIndexOf(".")); + if (entityPackage.contains(".")) { + return entityPackage.substring(0, entityPackage.lastIndexOf(".")) + ".mapper"; + } else { + return "mapper"; + } + } + } + + private String buildTablesClass(String entityClass, String tableName, Map propertyAndColumns, List defaultColumns) { // tableDefTemplate = " public static final @entityClassTableDef @tableField = new @entityClassTableDef(\"@tableName\");\n"; @@ -279,7 +293,7 @@ public class QueryEntityProcesser extends AbstractProcessor { writer.write(genContent); writer.flush(); - printMessage(">>>>> mybatis-flex success generate tables class: \n" + sourceFile.toUri()); +// printMessage(">>>>> mybatis-flex success generate tables class: \n" + sourceFile.toUri()); return; } @@ -317,7 +331,7 @@ public class QueryEntityProcesser extends AbstractProcessor { writer.write(genContent); writer.flush(); - printMessage(">>>>> mybatis-flex success generate tables class: \n" + genJavaFile.toURI()); +// printMessage(">>>>> mybatis-flex success generate tables class: \n" + genJavaFile.toURI()); } catch (IOException e) { e.printStackTrace(); @@ -349,7 +363,7 @@ public class QueryEntityProcesser extends AbstractProcessor { writer.write(genContent); writer.flush(); - printMessage(">>>>> mybatis-flex success generate mapper class: \n" + sourceFile.toUri()); +// printMessage(">>>>> mybatis-flex success generate mapper class: \n" + sourceFile.toUri()); return; } @@ -387,7 +401,7 @@ public class QueryEntityProcesser extends AbstractProcessor { writer.write(genContent); writer.flush(); - printMessage(">>>>> mybatis-flex success generate mapper class: \n" + genJavaFile.toURI()); +// printMessage(">>>>> mybatis-flex success generate mapper class: \n" + genJavaFile.toURI()); } catch (IOException e) { e.printStackTrace(); diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java deleted file mode 100644 index 7ea0170b..00000000 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * 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 - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * 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.mybatisflex.test.mapper; - -import com.mybatisflex.core.BaseMapper; -import com.mybatisflex.test.model.Account; -import org.apache.ibatis.annotations.Mapper; - -@Mapper -public interface AccountMapper extends BaseMapper { -} diff --git a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java b/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java deleted file mode 100644 index e1888fb5..00000000 --- a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * 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 - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * 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.mybatisflex.test.mapper; - -import com.mybatisflex.core.BaseMapper; -import com.mybatisflex.test.model.Account; - -public interface AccountMapper extends BaseMapper { -}