BudWk V7 builds a microservice development framework from scratch - 05 Database components

wk-starter-database

Component function

  • Definition of the public fields of the BaseModel table

Define the table field name, type, length, etc. through the Dao annotation @Column of the nutz framework:

@Data
public abstract class BaseModel implements Serializable {
    private static final long serialVersionUID = -762325615371339568L;

    @Column
    @Comment("创建人")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String createdBy;

    @Column
    @Comment("创建时间")
    @PrevInsert(now = true)
    private Long createdAt;

    @Column
    @Comment("修改人")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String updatedBy;

    @Column
    @Comment("修改时间")
    @PrevInsert(now = true)
    @PrevUpdate(now = true)
    private Long updatedAt;

    @Column
    @Comment("删除标记")
    @PrevInsert(els = @EL("$me.flag()"))
    @ColDefine(type = ColType.BOOLEAN)
    private Boolean delFlag;

    public String toJsonString() {
        return Json.toJson(this, JsonFormat.compact());
    }

    public Boolean flag() {
        return false;
    }

}
  • BaseService adds, deletes, modifies and checks common functions encapsulation

BaseServiceImpl.java mainly includes database addition, deletion, modification and query, custom SQL query, acquisition of Map objects, query of some fields, associated table query, optimistic lock encapsulation, pseudo deletion encapsulation, etc. The function is based on the secondary encapsulation of Nutz Dao. Learn about the documentation available at http://nutzam.com/core/dao/hello.html

  • Initialize table structure or alter table structure through Pojo class
# 创建表
Daos.createTablesInPackage(dao, packageName, false);
# 修改表结构
Daos.migration(dao, packageName, conf.getBoolean(PROP_DATABASE_TABLE_ADD, false),
                        conf.getBoolean(PROP_DATABASE_TABLE_DELETE, false),
                        conf.getBoolean(PROP_DATABASE_TABLE_CHECK, false));

Snowflake Primary Key

In the component startup class, register the primary key generator, see http://nutzam.com/core/dao/primary_key.html#ndoc-5

CustomMake.me().register("snowflake", ioc.get(SnowFlakeIdGenerator.class));
{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324158403&siteId=291194637