mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
优化 QueryColumn.as()
This commit is contained in:
parent
05687c2323
commit
5ea3b82aee
@ -102,7 +102,7 @@ public class QueryColumn implements CloneSupport<QueryColumn> {
|
||||
}
|
||||
|
||||
public <T> QueryColumn as(LambdaGetter<T> fn) {
|
||||
return as(LambdaUtil.getAsName(fn));
|
||||
return as(LambdaUtil.getAliasName(fn));
|
||||
}
|
||||
|
||||
public QueryColumn as(String alias) {
|
||||
|
||||
@ -833,6 +833,7 @@ public class TableInfo {
|
||||
|
||||
// <resultMap> 标签下的 <id> 标签映射
|
||||
for (IdInfo idInfo : primaryKeyList) {
|
||||
|
||||
ResultMapping mapping = new ResultMapping.Builder(configuration, idInfo.property,
|
||||
idInfo.column, idInfo.propertyType)
|
||||
.flags(CollectionUtil.newArrayList(ResultFlag.ID))
|
||||
@ -841,6 +842,7 @@ public class TableInfo {
|
||||
.build();
|
||||
resultMappings.add(mapping);
|
||||
|
||||
|
||||
if (ArrayUtil.isNotEmpty(idInfo.alias)) {
|
||||
// add alias mapping
|
||||
for (String alias : idInfo.alias) {
|
||||
@ -852,7 +854,17 @@ public class TableInfo {
|
||||
.build();
|
||||
resultMappings.add(aliasMapping);
|
||||
}
|
||||
}
|
||||
|
||||
// add property mapper for sql: select xxx as property ...
|
||||
if (!Objects.equals(idInfo.getColumn(), idInfo.getProperty())) {
|
||||
ResultMapping propertyMapping = new ResultMapping.Builder(configuration, idInfo.property,
|
||||
idInfo.property, idInfo.propertyType)
|
||||
.flags(CollectionUtil.newArrayList(ResultFlag.ID))
|
||||
.jdbcType(idInfo.getJdbcType())
|
||||
.typeHandler(idInfo.buildTypeHandler())
|
||||
.build();
|
||||
resultMappings.add(propertyMapping);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -43,13 +43,12 @@ public class LambdaUtil {
|
||||
}
|
||||
|
||||
|
||||
public static <T> String getAsName(LambdaGetter<T> getter) {
|
||||
public static <T> String getAliasName(LambdaGetter<T> getter) {
|
||||
QueryColumn queryColumn = getQueryColumn(getter);
|
||||
return queryColumn.getAlias();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T> QueryColumn getQueryColumn(LambdaGetter<T> getter) {
|
||||
SerializedLambda lambda = getSerializedLambda(getter);
|
||||
String methodName = lambda.getImplMethodName();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user