mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
fix: 修复fieldMapping 基础类型查询null的情况,添加测试代码
This commit is contained in:
parent
6a072a57ba
commit
2458f7dabe
@ -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
|
# 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: 12345678
|
password: Aa123456#
|
||||||
# driver-class-name:
|
# driver-class-name:
|
||||||
# datasource:
|
# datasource:
|
||||||
# driver-class-name: org.h2.Driver
|
# 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