mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
optimize QueryEntityProcesser.java
This commit is contained in:
parent
12f64a585a
commit
2127e1ba5f
@ -202,7 +202,7 @@ public class QueryEntityProcesser extends AbstractProcessor {
|
|||||||
//是否开启 mapper 生成功能
|
//是否开启 mapper 生成功能
|
||||||
if ("true".equalsIgnoreCase(mappersGenerateEnable)) {
|
if ("true".equalsIgnoreCase(mappersGenerateEnable)) {
|
||||||
String realMapperPackage = genMappersPackage == null || genMappersPackage.trim().length() == 0
|
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());
|
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<String, String> propertyAndColumns, List<String> defaultColumns) {
|
private String buildTablesClass(String entityClass, String tableName, Map<String, String> propertyAndColumns, List<String> defaultColumns) {
|
||||||
|
|
||||||
// tableDefTemplate = " public static final @entityClassTableDef @tableField = new @entityClassTableDef(\"@tableName\");\n";
|
// tableDefTemplate = " public static final @entityClassTableDef @tableField = new @entityClassTableDef(\"@tableName\");\n";
|
||||||
@ -279,7 +293,7 @@ public class QueryEntityProcesser extends AbstractProcessor {
|
|||||||
writer.write(genContent);
|
writer.write(genContent);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
|
||||||
printMessage(">>>>> mybatis-flex success generate tables class: \n" + sourceFile.toUri());
|
// printMessage(">>>>> mybatis-flex success generate tables class: \n" + sourceFile.toUri());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +331,7 @@ public class QueryEntityProcesser extends AbstractProcessor {
|
|||||||
writer.write(genContent);
|
writer.write(genContent);
|
||||||
writer.flush();
|
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) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -349,7 +363,7 @@ public class QueryEntityProcesser extends AbstractProcessor {
|
|||||||
writer.write(genContent);
|
writer.write(genContent);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
|
||||||
printMessage(">>>>> mybatis-flex success generate mapper class: \n" + sourceFile.toUri());
|
// printMessage(">>>>> mybatis-flex success generate mapper class: \n" + sourceFile.toUri());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,7 +401,7 @@ public class QueryEntityProcesser extends AbstractProcessor {
|
|||||||
writer.write(genContent);
|
writer.write(genContent);
|
||||||
writer.flush();
|
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) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.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>
|
|
||||||
* http://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.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<Account> {
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.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>
|
|
||||||
* http://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.mybatisflex.test.mapper;
|
|
||||||
|
|
||||||
import com.mybatisflex.core.BaseMapper;
|
|
||||||
import com.mybatisflex.test.model.Account;
|
|
||||||
|
|
||||||
public interface AccountMapper extends BaseMapper<Account> {
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user