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;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.core.constant.SqlConsts;
|
||||
import com.mybatisflex.core.query.*;
|
||||
import com.mybatisflex.core.table.TableDef;
|
||||
@ -39,7 +38,6 @@ import com.mybatisflex.core.util.LambdaUtil;
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public abstract class QueryModel<T extends QueryModel<T>> {
|
||||
|
||||
@Column(ignore = true)
|
||||
private QueryWrapper queryWrapper;
|
||||
|
||||
protected QueryWrapper queryWrapper() {
|
||||
|
||||
@ -74,6 +74,7 @@ public interface MapperQueryChain<T> extends ChainQuery<T> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
default T one() {
|
||||
return baseMapper().selectOneByQuery(toQueryWrapper());
|
||||
}
|
||||
@ -81,6 +82,7 @@ public interface MapperQueryChain<T> extends ChainQuery<T> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
default <R> R oneAs(Class<R> asType) {
|
||||
return baseMapper().selectOneByQueryAs(toQueryWrapper(), asType);
|
||||
}
|
||||
|
||||
@ -19,6 +19,10 @@ import com.mybatisflex.annotation.*;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
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.CollectionUtil;
|
||||
import com.mybatisflex.core.util.Reflectors;
|
||||
@ -61,6 +65,10 @@ public class TableInfoFactory {
|
||||
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> entityTableMap = new ConcurrentHashMap<>();
|
||||
@ -206,6 +214,9 @@ public class TableInfoFactory {
|
||||
// }
|
||||
|
||||
Class<?> fieldType = reflector.getGetterType(field.getName());
|
||||
if (ignoreColumnTypes.contains(fieldType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//满足以下 3 种情况,不支持该类型
|
||||
if ((column == null || column.typeHandler() == UnknownTypeHandler.class) // 未配置 typeHandler
|
||||
|
||||
@ -69,6 +69,10 @@ public class AccountController {
|
||||
DataSourceKey.use("ds2");
|
||||
accountMapper.insert(account);
|
||||
|
||||
// if (true) {
|
||||
// throw new RuntimeException("ex");
|
||||
// }
|
||||
|
||||
|
||||
return "add ok!";
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
# DataSource Config
|
||||
spring:
|
||||
# h2:
|
||||
# console:
|
||||
# enabled: true
|
||||
datasource:
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/flex_test
|
||||
username: root
|
||||
password: 123456
|
||||
#spring:
|
||||
# # h2:
|
||||
# # console:
|
||||
# # enabled: true
|
||||
# datasource:
|
||||
## driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://localhost:3306/flex_test
|
||||
# username: root
|
||||
# password: 123456
|
||||
# driver-class-name:
|
||||
# datasource:
|
||||
# driver-class-name: org.h2.Driver
|
||||
@ -36,13 +36,13 @@ spring:
|
||||
# url: jdbc:mysql://localhost:3306/flex_test
|
||||
# username: root
|
||||
# password: 12345678
|
||||
#mybatis-flex:
|
||||
# datasource:
|
||||
# ds1:
|
||||
# url: jdbc:mysql://127.0.0.1:3306/flex_test
|
||||
# username: root
|
||||
# password: 123456
|
||||
# ds2:
|
||||
# url: jdbc:mysql://127.0.0.1:3306/flex_test
|
||||
# username: root
|
||||
# password: 123456
|
||||
mybatis-flex:
|
||||
datasource:
|
||||
ds1:
|
||||
url: jdbc:mysql://127.0.0.1:3306/flex_test
|
||||
username: root
|
||||
password: 123456
|
||||
ds2:
|
||||
url: jdbc:mysql://127.0.0.1:3306/flex_test
|
||||
username: root
|
||||
password: 123456
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user