mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
feat: 添加对 ignore 字段自动映射的支持
This commit is contained in:
parent
7f3de5a21a
commit
9edc7545f9
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.mybatisflex.core.activerecord.query;
|
package com.mybatisflex.core.activerecord.query;
|
||||||
|
|
||||||
import com.mybatisflex.annotation.Column;
|
|
||||||
import com.mybatisflex.core.constant.SqlConsts;
|
import com.mybatisflex.core.constant.SqlConsts;
|
||||||
import com.mybatisflex.core.query.*;
|
import com.mybatisflex.core.query.*;
|
||||||
import com.mybatisflex.core.table.TableDef;
|
import com.mybatisflex.core.table.TableDef;
|
||||||
@ -39,7 +38,6 @@ import com.mybatisflex.core.util.LambdaUtil;
|
|||||||
@SuppressWarnings({"unused", "unchecked"})
|
@SuppressWarnings({"unused", "unchecked"})
|
||||||
public abstract class QueryModel<T extends QueryModel<T>> {
|
public abstract class QueryModel<T extends QueryModel<T>> {
|
||||||
|
|
||||||
@Column(ignore = true)
|
|
||||||
private QueryWrapper queryWrapper;
|
private QueryWrapper queryWrapper;
|
||||||
|
|
||||||
protected QueryWrapper queryWrapper() {
|
protected QueryWrapper queryWrapper() {
|
||||||
|
|||||||
@ -74,6 +74,7 @@ public interface MapperQueryChain<T> extends ChainQuery<T> {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
default T one() {
|
default T one() {
|
||||||
return baseMapper().selectOneByQuery(toQueryWrapper());
|
return baseMapper().selectOneByQuery(toQueryWrapper());
|
||||||
}
|
}
|
||||||
@ -81,6 +82,7 @@ public interface MapperQueryChain<T> extends ChainQuery<T> {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
default <R> R oneAs(Class<R> asType) {
|
default <R> R oneAs(Class<R> asType) {
|
||||||
return baseMapper().selectOneByQueryAs(toQueryWrapper(), asType);
|
return baseMapper().selectOneByQueryAs(toQueryWrapper(), asType);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,10 @@ import com.mybatisflex.annotation.*;
|
|||||||
import com.mybatisflex.core.BaseMapper;
|
import com.mybatisflex.core.BaseMapper;
|
||||||
import com.mybatisflex.core.FlexGlobalConfig;
|
import com.mybatisflex.core.FlexGlobalConfig;
|
||||||
import com.mybatisflex.core.exception.FlexExceptions;
|
import com.mybatisflex.core.exception.FlexExceptions;
|
||||||
|
import com.mybatisflex.core.query.QueryChain;
|
||||||
|
import com.mybatisflex.core.query.QueryColumn;
|
||||||
|
import com.mybatisflex.core.query.QueryCondition;
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.core.util.ClassUtil;
|
import com.mybatisflex.core.util.ClassUtil;
|
||||||
import com.mybatisflex.core.util.CollectionUtil;
|
import com.mybatisflex.core.util.CollectionUtil;
|
||||||
import com.mybatisflex.core.util.Reflectors;
|
import com.mybatisflex.core.util.Reflectors;
|
||||||
@ -61,6 +65,10 @@ public class TableInfoFactory {
|
|||||||
char.class, String.class, Character.class
|
char.class, String.class, Character.class
|
||||||
);
|
);
|
||||||
|
|
||||||
|
static final Set<Class<?>> ignoreColumnTypes = CollectionUtil.newHashSet(
|
||||||
|
QueryWrapper.class, QueryColumn.class, QueryCondition.class, QueryChain.class
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
private static final Map<Class<?>, TableInfo> mapperTableInfoMap = new ConcurrentHashMap<>();
|
private static final Map<Class<?>, TableInfo> mapperTableInfoMap = new ConcurrentHashMap<>();
|
||||||
private static final Map<Class<?>, TableInfo> entityTableMap = new ConcurrentHashMap<>();
|
private static final Map<Class<?>, TableInfo> entityTableMap = new ConcurrentHashMap<>();
|
||||||
@ -206,6 +214,9 @@ public class TableInfoFactory {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
Class<?> fieldType = reflector.getGetterType(field.getName());
|
Class<?> fieldType = reflector.getGetterType(field.getName());
|
||||||
|
if (ignoreColumnTypes.contains(fieldType)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//满足以下 3 种情况,不支持该类型
|
//满足以下 3 种情况,不支持该类型
|
||||||
if ((column == null || column.typeHandler() == UnknownTypeHandler.class) // 未配置 typeHandler
|
if ((column == null || column.typeHandler() == UnknownTypeHandler.class) // 未配置 typeHandler
|
||||||
|
|||||||
@ -69,6 +69,10 @@ public class AccountController {
|
|||||||
DataSourceKey.use("ds2");
|
DataSourceKey.use("ds2");
|
||||||
accountMapper.insert(account);
|
accountMapper.insert(account);
|
||||||
|
|
||||||
|
// if (true) {
|
||||||
|
// throw new RuntimeException("ex");
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
return "add ok!";
|
return "add ok!";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
# DataSource Config
|
# DataSource Config
|
||||||
spring:
|
#spring:
|
||||||
# h2:
|
# # h2:
|
||||||
# console:
|
# # console:
|
||||||
# enabled: true
|
# # enabled: true
|
||||||
datasource:
|
# datasource:
|
||||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
## driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3306/flex_test
|
# url: jdbc:mysql://localhost:3306/flex_test
|
||||||
username: root
|
# username: root
|
||||||
password: 123456
|
# password: 123456
|
||||||
# driver-class-name:
|
# driver-class-name:
|
||||||
# datasource:
|
# datasource:
|
||||||
# driver-class-name: org.h2.Driver
|
# driver-class-name: org.h2.Driver
|
||||||
@ -36,13 +36,13 @@ spring:
|
|||||||
# url: jdbc:mysql://localhost:3306/flex_test
|
# url: jdbc:mysql://localhost:3306/flex_test
|
||||||
# username: root
|
# username: root
|
||||||
# password: 12345678
|
# password: 12345678
|
||||||
#mybatis-flex:
|
mybatis-flex:
|
||||||
# datasource:
|
datasource:
|
||||||
# ds1:
|
ds1:
|
||||||
# url: jdbc:mysql://127.0.0.1:3306/flex_test
|
url: jdbc:mysql://127.0.0.1:3306/flex_test
|
||||||
# username: root
|
username: root
|
||||||
# password: 123456
|
password: 123456
|
||||||
# ds2:
|
ds2:
|
||||||
# url: jdbc:mysql://127.0.0.1:3306/flex_test
|
url: jdbc:mysql://127.0.0.1:3306/flex_test
|
||||||
# username: root
|
username: root
|
||||||
# password: 123456
|
password: 123456
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user