您现在的位置是: 首页 > 杂七杂八 【代码片段】MySQL新建表添加基础字段

【代码片段】MySQL新建表添加基础字段

2020-09-04 杂七杂八 1999人已围观 3482次浏览

简介【代码片段】MySQL新建表添加基础字段

MySQL数据库表中,经常会用到的三个字段

SQL建表时,直接插入

gmt_create datetime null comment '创建时间',
gmt_modified datetime null comment '修改时间',
is_deleted tinyint(1) unsigned default 0 not null comment '逻辑删除标记'

或者在已有的表最后插入

alter table table_name
   add gmt_create datetime null comment '创建时间';

alter table table_name
   add gmt_modified datetime null comment '修改时间';

alter table table_name
   add is_deleted tinyint(1) default 0 not null comment '逻辑删除标记';

对应 Java 代码,基于 MyBatis-Plus 时间字段自动填充、软删除

/**
 * 创建时间
 */
@TableField(value = "gmt_create", fill = FieldFill.INSERT)
private String gmtCreate;

/**
 * 修改时间
 */
@TableField(value = "gmt_modified", fill = FieldFill.INSERT_UPDATE)
private String gmtModified;

/**
 * 逻辑删除标记
 */
@TableLogic
private Integer isDeleted;

很赞哦! (0)

站长推荐

站点信息

  • 网站地图