mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
feature:add more Date type for defaultSupportColumnTypes
This commit is contained in:
parent
9fc1ca1ca2
commit
5f551c4d1a
@ -18,6 +18,7 @@ package com.mybatisflex.processer;
|
|||||||
|
|
||||||
import com.mybatisflex.annotation.Column;
|
import com.mybatisflex.annotation.Column;
|
||||||
import com.mybatisflex.annotation.Table;
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import org.apache.ibatis.type.UnknownTypeHandler;
|
||||||
|
|
||||||
import javax.annotation.processing.AbstractProcessor;
|
import javax.annotation.processing.AbstractProcessor;
|
||||||
import javax.annotation.processing.Filer;
|
import javax.annotation.processing.Filer;
|
||||||
@ -35,9 +36,10 @@ import javax.tools.JavaFileObject;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.time.LocalDate;
|
import java.sql.Time;
|
||||||
import java.time.LocalDateTime;
|
import java.sql.Timestamp;
|
||||||
import java.time.LocalTime;
|
import java.time.*;
|
||||||
|
import java.time.chrono.JapaneseDate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@ -50,10 +52,13 @@ public class QueryEntityProcesser extends AbstractProcessor {
|
|||||||
float.class.getName(), Float.class.getName(),
|
float.class.getName(), Float.class.getName(),
|
||||||
double.class.getName(), Double.class.getName(),
|
double.class.getName(), Double.class.getName(),
|
||||||
boolean.class.getName(), Boolean.class.getName(),
|
boolean.class.getName(), Boolean.class.getName(),
|
||||||
Date.class.getName(), java.sql.Date.class.getName(), LocalDate.class.getName(), LocalDateTime.class.getName(), LocalTime.class.getName(),
|
Date.class.getName(), java.sql.Date.class.getName(), Time.class.getName(), Timestamp.class.getName(),
|
||||||
|
Instant.class.getName(), LocalDate.class.getName(), LocalDateTime.class.getName(), LocalTime.class.getName(),
|
||||||
|
OffsetDateTime.class.getName(), OffsetTime.class.getName(), ZonedDateTime.class.getName(),
|
||||||
|
Year.class.getName(), Month.class.getName(), YearMonth.class.getName(), JapaneseDate.class.getName(),
|
||||||
byte[].class.getName(), Byte[].class.getName(),
|
byte[].class.getName(), Byte[].class.getName(),
|
||||||
BigInteger.class.getName(), BigDecimal.class.getName(),
|
BigInteger.class.getName(), BigDecimal.class.getName(),
|
||||||
char.class.getName(), String.class.getName()
|
char.class.getName(), String.class.getName(), Character.class.getName()
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final String classTableTemplate = "package @package;\n" +
|
private static final String classTableTemplate = "package @package;\n" +
|
||||||
@ -148,16 +153,19 @@ public class QueryEntityProcesser extends AbstractProcessor {
|
|||||||
if (ElementKind.FIELD == fieldElement.getKind()) {
|
if (ElementKind.FIELD == fieldElement.getKind()) {
|
||||||
|
|
||||||
TypeMirror typeMirror = fieldElement.asType();
|
TypeMirror typeMirror = fieldElement.asType();
|
||||||
// Element typeElement = typeUtils.asElement(typeMirror);
|
|
||||||
|
|
||||||
if (!defaultSupportColumnTypes.contains(typeMirror.toString())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Column column = fieldElement.getAnnotation(Column.class);
|
Column column = fieldElement.getAnnotation(Column.class);
|
||||||
if (column != null && column.ignore()) {
|
if (column != null && column.ignore()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//未配置 typeHandler 的情况下,只支持基本数据类型,不支持比如 list set 或者自定义的类等
|
||||||
|
if ((column == null || column.typeHandler() == UnknownTypeHandler.class)
|
||||||
|
&& !defaultSupportColumnTypes.contains(typeMirror.toString())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
String columnName = column != null && column.value().trim().length() > 0 ? column.value() : camelToUnderline(fieldElement.toString());
|
String columnName = column != null && column.value().trim().length() > 0 ? column.value() : camelToUnderline(fieldElement.toString());
|
||||||
propertyAndColumns.put(fieldElement.toString(), columnName);
|
propertyAndColumns.put(fieldElement.toString(), columnName);
|
||||||
|
|
||||||
|
|||||||
@ -37,14 +37,16 @@ import java.lang.reflect.ParameterizedType;
|
|||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.time.LocalDate;
|
import java.sql.Time;
|
||||||
import java.time.LocalDateTime;
|
import java.sql.Timestamp;
|
||||||
import java.time.LocalTime;
|
import java.time.*;
|
||||||
|
import java.time.chrono.JapaneseDate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class TableInfos {
|
public class TableInfos {
|
||||||
|
|
||||||
|
|
||||||
private static final Set<Class<?>> defaultSupportColumnTypes = CollectionUtil.newHashSet(
|
private static final Set<Class<?>> defaultSupportColumnTypes = CollectionUtil.newHashSet(
|
||||||
int.class, Integer.class,
|
int.class, Integer.class,
|
||||||
short.class, Short.class,
|
short.class, Short.class,
|
||||||
@ -52,10 +54,12 @@ public class TableInfos {
|
|||||||
float.class, Float.class,
|
float.class, Float.class,
|
||||||
double.class, Double.class,
|
double.class, Double.class,
|
||||||
boolean.class, Boolean.class,
|
boolean.class, Boolean.class,
|
||||||
Date.class, java.sql.Date.class, LocalDate.class, LocalDateTime.class, LocalTime.class,
|
Date.class, java.sql.Date.class, Time.class, Timestamp.class,
|
||||||
|
Instant.class, LocalDate.class, LocalDateTime.class, LocalTime.class, OffsetDateTime.class, OffsetTime.class, ZonedDateTime.class,
|
||||||
|
Year.class, Month.class, YearMonth.class, JapaneseDate.class,
|
||||||
byte[].class, Byte[].class,
|
byte[].class, Byte[].class,
|
||||||
BigInteger.class, BigDecimal.class,
|
BigInteger.class, BigDecimal.class,
|
||||||
char.class, String.class
|
char.class, String.class, Character.class
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -206,7 +210,7 @@ public class TableInfos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (column != null && column.jdbcType() != JdbcType.UNDEFINED){
|
if (column != null && column.jdbcType() != JdbcType.UNDEFINED) {
|
||||||
columnInfo.setJdbcType(column.jdbcType());
|
columnInfo.setJdbcType(column.jdbcType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user