mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
commit
0778ab325a
@ -136,7 +136,7 @@ public final class SqlConsts {
|
|||||||
// === SQL 函数名 ===
|
// === SQL 函数名 ===
|
||||||
|
|
||||||
public static final String SUM = "SUM";
|
public static final String SUM = "SUM";
|
||||||
public static final String MAX = "MIX";
|
public static final String MAX = "MAX";
|
||||||
public static final String MIN = "MIN";
|
public static final String MIN = "MIN";
|
||||||
public static final String AVG = "AVG";
|
public static final String AVG = "AVG";
|
||||||
public static final String DAY = "DAY";
|
public static final String DAY = "DAY";
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
* <p>
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* <p>
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.mybatisflex.processor;
|
package com.mybatisflex.processor;
|
||||||
|
|
||||||
@ -41,6 +41,7 @@ import java.sql.Timestamp;
|
|||||||
import java.time.*;
|
import java.time.*;
|
||||||
import java.time.chrono.JapaneseDate;
|
import java.time.chrono.JapaneseDate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@ -162,23 +163,14 @@ public class QueryEntityProcessor extends AbstractProcessor {
|
|||||||
String[] entityIgnoreSuffixes = props.getProperties().getProperty("processor.entity.ignoreSuffixes", "").split(",");
|
String[] entityIgnoreSuffixes = props.getProperties().getProperty("processor.entity.ignoreSuffixes", "").split(",");
|
||||||
|
|
||||||
|
|
||||||
StringBuilder guessPackage = new StringBuilder();
|
AtomicReference<String> entityClassName = new AtomicReference<>();
|
||||||
|
|
||||||
StringBuilder tablesContent = new StringBuilder();
|
StringBuilder tablesContent = new StringBuilder();
|
||||||
roundEnv.getElementsAnnotatedWith(Table.class).forEach((Consumer<Element>) entityClassElement -> {
|
roundEnv.getElementsAnnotatedWith(Table.class).forEach((Consumer<Element>) entityClassElement -> {
|
||||||
|
|
||||||
Table table = entityClassElement.getAnnotation(Table.class);
|
Table table = entityClassElement.getAnnotation(Table.class);
|
||||||
|
|
||||||
//init genPackage
|
entityClassName.set(entityClassElement.toString());
|
||||||
if ((genTablesPackage == null || genTablesPackage.trim().length() == 0)
|
|
||||||
&& guessPackage.length() == 0) {
|
|
||||||
String entityClassName = entityClassElement.toString();
|
|
||||||
if (!entityClassName.contains(".")) {
|
|
||||||
guessPackage.append("table");// = "table";
|
|
||||||
} else {
|
|
||||||
guessPackage.append(entityClassName.substring(0, entityClassName.lastIndexOf(".")) + ".table");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String schema = table != null && table.value().trim().length() != 0
|
String schema = table != null && table.value().trim().length() != 0
|
||||||
? table.schema()
|
? table.schema()
|
||||||
@ -216,7 +208,7 @@ public class QueryEntityProcessor extends AbstractProcessor {
|
|||||||
}
|
}
|
||||||
//每一个 entity 生成一个独立的文件
|
//每一个 entity 生成一个独立的文件
|
||||||
else {
|
else {
|
||||||
String realGenPackage = genTablesPackage == null || genTablesPackage.trim().length() == 0 ? guessPackage.toString() : genTablesPackage;
|
String realGenPackage = isEmpty(genMappersPackage) ? guessTablesPackage(entityClassName.get()) : genTablesPackage;
|
||||||
String content = buildTablesClass(entitySimpleName, schema, tableName, propertyAndColumns, defaultColumns, tablesNameStyle
|
String content = buildTablesClass(entitySimpleName, schema, tableName, propertyAndColumns, defaultColumns, tablesNameStyle
|
||||||
, tablesDefSuffix, realGenPackage, allInTables);
|
, tablesDefSuffix, realGenPackage, allInTables);
|
||||||
genClass(genPath, realGenPackage, entitySimpleName + "TableDef", content);
|
genClass(genPath, realGenPackage, entitySimpleName + "TableDef", content);
|
||||||
@ -224,14 +216,13 @@ public class QueryEntityProcessor extends AbstractProcessor {
|
|||||||
|
|
||||||
//是否开启 mapper 生成功能
|
//是否开启 mapper 生成功能
|
||||||
if ("true".equalsIgnoreCase(mappersGenerateEnable) && table.mapperGenerateEnable()) {
|
if ("true".equalsIgnoreCase(mappersGenerateEnable) && table.mapperGenerateEnable()) {
|
||||||
String realMapperPackage = genMappersPackage == null || genMappersPackage.trim().length() == 0
|
String realMapperPackage = isEmpty(genMappersPackage) ? guessMapperPackage(entityClassElement.toString()) : genMappersPackage;
|
||||||
? guessMapperPackage(entityClassElement.toString()) : genMappersPackage;
|
|
||||||
genMapperClass(genPath, realMapperPackage, entityClassElement.toString(), baseMapperClass, entitySimpleName);
|
genMapperClass(genPath, realMapperPackage, entityClassElement.toString(), baseMapperClass, entitySimpleName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (allInTables && tablesContent.length() > 0) {
|
if (allInTables && tablesContent.length() > 0) {
|
||||||
String realGenPackage = genTablesPackage == null || genTablesPackage.trim().length() == 0 ? guessPackage.toString() : genTablesPackage;
|
String realGenPackage = isEmpty(genTablesPackage) ? guessTablesPackage(entityClassName.get()) : genTablesPackage;
|
||||||
genTablesClass(genPath, realGenPackage, className, tablesContent.toString());
|
genTablesClass(genPath, realGenPackage, className, tablesContent.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,6 +231,20 @@ public class QueryEntityProcessor extends AbstractProcessor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isEmpty(String str) {
|
||||||
|
return str == null || str.trim().length() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String guessTablesPackage(String entityClassName) {
|
||||||
|
StringBuilder guessPackage = new StringBuilder();
|
||||||
|
if (!entityClassName.contains(".")) {
|
||||||
|
guessPackage.append("table");// = "table";
|
||||||
|
} else {
|
||||||
|
guessPackage.append(entityClassName, 0, entityClassName.lastIndexOf(".")).append(".table");
|
||||||
|
}
|
||||||
|
return guessPackage.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void fillPropertyAndColumns(Map<String, String> propertyAndColumns, List<String> defaultColumns, TypeElement classElement, boolean camelToUnderline) {
|
private void fillPropertyAndColumns(Map<String, String> propertyAndColumns, List<String> defaultColumns, TypeElement classElement, boolean camelToUnderline) {
|
||||||
for (Element fieldElement : classElement.getEnclosedElements()) {
|
for (Element fieldElement : classElement.getEnclosedElements()) {
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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.entity;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 王帅
|
||||||
|
* @since 2023-06-16
|
||||||
|
*/
|
||||||
|
@Table("test")
|
||||||
|
public class Test {
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user