mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 09:38:26 +08:00
commit
84c428c5a7
@ -16,8 +16,8 @@
|
||||
|
||||
package com.mybatisflex.processor;
|
||||
|
||||
import com.mybatisflex.annotation.ColumnAlias;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.ColumnAlias;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import com.mybatisflex.processor.builder.ContentBuilder;
|
||||
import com.mybatisflex.processor.config.ConfigurationKey;
|
||||
@ -152,15 +152,12 @@ public class MybatisFlexProcessor extends AbstractProcessor {
|
||||
List<ColumnInfo> columnInfoList = new LinkedList<>();
|
||||
// 默认查询的属性,非 isLarge 字段
|
||||
List<String> defaultColumns = new ArrayList<>();
|
||||
|
||||
TypeElement classElement = (TypeElement) entityClassElement;
|
||||
|
||||
do {
|
||||
// 获取类属性和默认查询字段
|
||||
fillColumnInfoList(columnInfoList, defaultColumns, classElement, table.camelToUnderline());
|
||||
classElement = (TypeElement) typeUtils.asElement(classElement.getSuperclass());
|
||||
} while (classElement != null);
|
||||
|
||||
classElement = (TypeElement) entityClassElement;
|
||||
do {
|
||||
fillColumnInfoList(columnInfoList, defaultColumns, (TypeElement) entityClassElement, classElement, table.camelToUnderline());
|
||||
classElement = (TypeElement) typeUtils.asElement(classElement.getSuperclass());
|
||||
} while (classElement != null);
|
||||
|
||||
@ -223,11 +220,8 @@ public class MybatisFlexProcessor extends AbstractProcessor {
|
||||
return SourceVersion.latestSupported();
|
||||
}
|
||||
|
||||
private void fillColumnInfoList(List<ColumnInfo> columnInfoList, List<String> defaultColumns, TypeElement classElement, boolean camelToUnderline) {
|
||||
|
||||
List<? extends Element> enclosedElements = classElement.getEnclosedElements();
|
||||
|
||||
for (Element fieldElement : enclosedElements) {
|
||||
private void fillColumnInfoList(List<ColumnInfo> columnInfoList, List<String> defaultColumns, TypeElement baseElement, TypeElement classElement, boolean camelToUnderline) {
|
||||
for (Element fieldElement : classElement.getEnclosedElements()) {
|
||||
|
||||
// all fields
|
||||
if (ElementKind.FIELD == fieldElement.getKind()) {
|
||||
@ -290,8 +284,7 @@ public class MybatisFlexProcessor extends AbstractProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String[] alias = getColumnAliasByGetterMethod(enclosedElements, property);
|
||||
String[] alias = getColumnAliasByGetterMethod(baseElement, property);
|
||||
if (alias == null || alias.length == 0) {
|
||||
ColumnAlias columnAlias = fieldElement.getAnnotation(ColumnAlias.class);
|
||||
if (columnAlias != null) {
|
||||
@ -314,14 +307,14 @@ public class MybatisFlexProcessor extends AbstractProcessor {
|
||||
}
|
||||
|
||||
|
||||
private String[] getColumnAliasByGetterMethod(List<? extends Element> enclosedElements, String property) {
|
||||
for (Element enclosedElement : enclosedElements) {
|
||||
private String[] getColumnAliasByGetterMethod(TypeElement baseElement, String property) {
|
||||
for (Element enclosedElement : baseElement.getEnclosedElements()) {
|
||||
if (ElementKind.METHOD == enclosedElement.getKind()) {
|
||||
String methodName = enclosedElement.toString();
|
||||
if (StrUtil.isGetterMethod(methodName, property)) {
|
||||
ColumnAlias asType = enclosedElement.getAnnotation(ColumnAlias.class);
|
||||
if (asType != null) {
|
||||
return asType.value();
|
||||
ColumnAlias columnAlias = enclosedElement.getAnnotation(ColumnAlias.class);
|
||||
if (columnAlias != null) {
|
||||
return columnAlias.value();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -114,9 +114,9 @@ public class StrUtil {
|
||||
|
||||
public static boolean isGetterMethod(String methodName, String property) {
|
||||
if (methodName.startsWith("get") && methodName.length() > 3) {
|
||||
return firstCharToUpperCase(property).equals(methodName.substring(3));
|
||||
return firstCharToUpperCase(property).concat("()").equals(methodName.substring(3));
|
||||
} else if (methodName.startsWith("is") && methodName.length() > 2) {
|
||||
return firstCharToUpperCase(property).equals(methodName.substring(2));
|
||||
return firstCharToUpperCase(property).concat("()").equals(methodName.substring(2));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -31,9 +31,9 @@ public class Outer extends IdEntity<Integer> {
|
||||
private Inner inner;
|
||||
|
||||
@Override
|
||||
@ColumnAlias("test_id")
|
||||
public void setId(Integer id) {
|
||||
super.setId(id);
|
||||
@ColumnAlias("outer_id")
|
||||
public Integer getId() {
|
||||
return super.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user