# 核心基类

# BaseDO (opens new window)

全限定名:pro.haichuang.framework.mybatis.domain.BaseDO (opens new window)

实体基类

该类为实体基类

警告

所有实体映射DO层必须继承pro.haichuang.framework.mybatis.domain.BaseDO

注意

BaseDO 基类自带三个默认字段,新建数据库表时必须与其一一对应

/**
 * 唯一ID
 * 
 * <p>默认使用雪花ID, 默认带上Validate的 {@code Group.Update} 类型验证
 */
@ApiModelProperty("ID")
@TableId(value = "id", type = IdType.ASSIGN_ID)
@JsonSerialize(using = ToStringSerializer.class)
@NotNull(message = "ID不能为空", groups = Group.Update.class)
private Long id;

/**
 * 创建时间
 *
 * <p>新增时将自动填充当前时间
 */
@ApiModelProperty(value = "创建时间", hidden = true)
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;

/**
 * 最后修改时间
 * 
 * <p>新增与修改时自动填充当前时间
 */
@ApiModelProperty(value = "最后修改时间", hidden = true)
@TableField(value = "modify_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime modifyTime;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

👇示例👇

/**
 * 测试DO
 *
 * @author JiYinchuan
 * @since 1.1.0.211021
 */
@ApiIgnore
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("test")
public class TestDO extends BaseDO {
    private static final long serialVersionUID = 1L;

    /**
     * 名称
     */
    @TableField("name")
    private String name;
    
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# BaseService (opens new window)

全限定名:pro.haichuang.framework.mybatis.service.BaseService (opens new window)

Service基类

该类为Service基类,二次封装了Mybatis中的部分方法,与架构相结合

警告

所有实体映射Service层必须继承BaseService

👇示例👇

/**
 * 测试表 Service
 *
 * @author JiYinchuan
 * @since 1.1.0.211021
 */
public interface TestService extends BaseService<TestDO> {

}
1
2
3
4
5
6
7
8
9

# BaseServiceImpl (opens new window)

全限定名:pro.haichuang.framework.mybatis.service.BaseServiceImpl (opens new window)

ServiceImpl基类

该类为ServiceImpl基类,继承自MybatisServiceImpl,实现BaseService

警告

所有实体映射ServiceImpl层必须继承BaseServiceImpl (opens new window))

👇示例👇

/**
 * 测试表 ServiceImpl
 *
 * @author JiYinchuan
 * @since 1.1.0.211021
 */
@Service
public class TestServiceImpl extends BaseServiceImpl<TestMapper, TestDO> implements TestService {

}
1
2
3
4
5
6
7
8
9
10

# BaseMapper (opens new window)

全限定名:com.baomidou.mybatisplus.core.mapper.BaseMapper

Mapper基类

该类为Mapper基类,Mybatis的默认BaseMapper接口

警告

所有实体映射Mapper层必须继承BaseMapper

👇示例👇

/**
 * 测试表 Mapper
 *
 * @author JiYinchuan
 * @since 1.1.0.211021
 */
@Repository
@Mapper
public interface TestMapper extends BaseMapper<TestDO> {

}
1
2
3
4
5
6
7
8
9
10
11
Last Updated: 10/28/2021, 5:59:51 PM