mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
!372 fix: 修复fieldMapping 基础类型查询null的情况
Merge pull request !372 from 关梦园/main
This commit is contained in:
commit
559c0e7470
@ -26,6 +26,8 @@ import com.mybatisflex.core.util.CollectionUtil;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
|
||||
import static com.mybatisflex.core.table.TableInfoFactory.defaultSupportColumnTypes;
|
||||
|
||||
/**
|
||||
* 属性查询管理。
|
||||
*
|
||||
@ -87,6 +89,8 @@ public class FieldQueryManager {
|
||||
Class<?> componentType = filedType.getComponentType();
|
||||
List<?> objects = mapper.selectListByQueryAs(queryWrapper, componentType);
|
||||
value = getArrayValue(componentType, objects);
|
||||
} else if (defaultSupportColumnTypes.contains(filedType)) {
|
||||
value = mapper.selectObjectByQueryAs(queryWrapper, filedType);
|
||||
} else {
|
||||
value = mapper.selectOneByQueryAs(queryWrapper, filedType);
|
||||
// 循环查询嵌套类
|
||||
|
||||
@ -50,7 +50,7 @@ public class TableInfoFactory {
|
||||
private TableInfoFactory() {
|
||||
}
|
||||
|
||||
static final Set<Class<?>> defaultSupportColumnTypes = CollectionUtil.newHashSet(
|
||||
public static final Set<Class<?>> defaultSupportColumnTypes = CollectionUtil.newHashSet(
|
||||
int.class, Integer.class,
|
||||
short.class, Short.class,
|
||||
long.class, Long.class,
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
package com.mybatisflex.test.model;
|
||||
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import com.mybatisflex.core.activerecord.Model;
|
||||
import com.mybatisflex.core.keygen.KeyGenerators;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@Table("field_mapping")
|
||||
public class FieldMapping extends Model<FieldMapping> {
|
||||
@Id(keyType = KeyType.Generator,value = KeyGenerators.snowFlakeId)
|
||||
private String id;
|
||||
@Column(ignore = true)
|
||||
private Date innerDate;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static FieldMapping create() {
|
||||
return new FieldMapping();
|
||||
}
|
||||
|
||||
public FieldMapping setId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getInnerDate() {
|
||||
return innerDate;
|
||||
}
|
||||
|
||||
public FieldMapping setInnerDate(Date innerDate) {
|
||||
this.innerDate = innerDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FieldMapping that = (FieldMapping) o;
|
||||
return Objects.equals(id, that.id) && Objects.equals(innerDate, that.innerDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, innerDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FieldMapping{" +
|
||||
"id='" + id + '\'' +
|
||||
", innerDate=" + innerDate +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,71 @@
|
||||
package com.mybatisflex.test.model;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import com.mybatisflex.core.activerecord.Model;
|
||||
import com.mybatisflex.core.keygen.KeyGenerators;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@Table("field_mapping_inner")
|
||||
public class FieldMappingInner extends Model<FieldMappingInner> {
|
||||
@Id(keyType = KeyType.Generator,value = KeyGenerators.snowFlakeId)
|
||||
private String id;
|
||||
private String outId;
|
||||
private Date createDate;
|
||||
|
||||
public static FieldMappingInner create() {
|
||||
return new FieldMappingInner();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public FieldMappingInner setId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getOutId() {
|
||||
return outId;
|
||||
}
|
||||
|
||||
public FieldMappingInner setOutId(String outId) {
|
||||
this.outId = outId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
|
||||
public FieldMappingInner setCreateDate(Date createDate) {
|
||||
this.createDate = createDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FieldMappingInner that = (FieldMappingInner) o;
|
||||
return Objects.equals(id, that.id) && Objects.equals(outId, that.outId) && Objects.equals(createDate, that.createDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, outId, createDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FieldMappingInner{" +
|
||||
"id='" + id + '\'' +
|
||||
", outId='" + outId + '\'' +
|
||||
", createDate=" + createDate +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,7 @@ spring:
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/flex_test
|
||||
username: root
|
||||
password: 12345678
|
||||
password: Aa123456#
|
||||
# driver-class-name:
|
||||
# datasource:
|
||||
# driver-class-name: org.h2.Driver
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
create table field_mapping
|
||||
(
|
||||
id varchar(255) not null
|
||||
primary key
|
||||
);
|
||||
create table field_mapping_inner
|
||||
(
|
||||
id varchar(255) not null
|
||||
primary key,
|
||||
out_id varchar(255) null,
|
||||
create_date timestamp null
|
||||
);
|
||||
@ -0,0 +1,30 @@
|
||||
package com.mybatisflex.test.service;
|
||||
|
||||
import com.mybatisflex.test.mapper.FieldMappingInnerMapper;
|
||||
import com.mybatisflex.test.mapper.FieldMappingMapper;
|
||||
import com.mybatisflex.test.model.FieldMapping;
|
||||
import com.mybatisflex.test.model.FieldMappingInner;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@SpringBootTest
|
||||
public class FieldMappingTest {
|
||||
@Autowired
|
||||
FieldMappingMapper fieldMappingMapper;
|
||||
@Autowired
|
||||
FieldMappingInnerMapper fieldMappingInnerMapper;
|
||||
@Test
|
||||
void testFieldMapping() {
|
||||
String fieldId = FieldMapping.create().saveOpt().get().getId();
|
||||
FieldMappingInner.create().setCreateDate(new Date()).setOutId(fieldId).save();
|
||||
FieldMapping.create()
|
||||
.withFields()
|
||||
.fieldMapping(FieldMapping::getInnerDate, con ->
|
||||
FieldMappingInner.create().select(FieldMappingInner::getCreateDate).where(FieldMappingInner::getOutId).eq(con.getId()).toQueryWrapper()
|
||||
)
|
||||
.list().forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user