不灭的焱

革命尚未成功,同志仍须努力 下载Java21

作者:AlbertWen  添加时间:2026-06-15 20:59:32  修改时间:2026-06-24 17:23:44  分类:18.系统设计/UML建模  编辑

可以。下面按你前面确定的规范来:数据库字段尽量不使用 is_ 前缀,改成更简洁的 状态形容词字段xxx_flag 字段

推荐原则:

is_deleted   → deleted
is_enabled   → enabled
is_default   → default_flag
is_required  → required_flag

其中:

  • 能直接用形容词表达的,用简洁字段:deleted、enabled、visible、locked

  • 容易和关键字、业务名冲突的,用 _flag:default_flag、public_flag、system_flag

  • 数据库存储类型统一建议:tinyint not null default 0/1

  • 注释统一写:是否xxx:0-否,1-是

1. 通用基础类

旧字段名 新规范字段名 字段类型 默认值 注释
is_deleted deleted tinyint 0 是否删除:0-否,1-是
is_enabled enabled tinyint 1 是否启用:0-否,1-是
is_disabled disabled tinyint 0 是否禁用:0-否,1-是
is_active active tinyint 1 是否激活:0-否,1-是
is_valid valid tinyint 1 是否有效:0-否,1-是
is_invalid invalid_flag tinyint 0 是否无效:0-否,1-是
is_available available tinyint 1 是否可用:0-否,1-是
is_locked locked tinyint 0 是否锁定:0-否,1-是
is_frozen frozen tinyint 0 是否冻结:0-否,1-是

示例:

deleted tinyint not null default 0 comment '是否删除:0-否,1-是',
enabled tinyint not null default 1 comment '是否启用:0-否,1-是',
locked tinyint not null default 0 comment '是否锁定:0-否,1-是'

2. 系统内置 / 默认 / 管理类

旧字段名 新规范字段名 字段类型 默认值 注释
is_default default_flag tinyint 0 是否默认:0-否,1-是
is_system system_flag tinyint 0 是否系统内置:0-否,1-是
is_builtin builtin_flag tinyint 0 是否内置:0-否,1-是
is_admin admin_flag tinyint 0 是否管理员:0-否,1-是
is_super_admin super_admin_flag tinyint 0 是否超级管理员:0-否,1-是
is_master master_flag tinyint 0 是否主记录:0-否,1-是
is_primary primary_flag tinyint 0 是否主要:0-否,1-是
is_global global_flag tinyint 0 是否全局:0-否,1-是

default、system、primary 这类词单独作为字段名不够稳妥,所以建议加 _flag。

default_flag tinyint not null default 0 comment '是否默认:0-否,1-是',
system_flag tinyint not null default 0 comment '是否系统内置:0-否,1-是',
admin_flag tinyint not null default 0 comment '是否管理员:0-否,1-是'

3. 显示 / 权限 / 访问控制类

旧字段名 新规范字段名 字段类型 默认值 注释
is_visible visible tinyint 1 是否可见:0-否,1-是
is_hidden hidden tinyint 0 是否隐藏:0-否,1-是
is_public public_flag tinyint 0 是否公开:0-否,1-是
is_private private_flag tinyint 0 是否私有:0-否,1-是
is_open open_flag tinyint 0 是否开放:0-否,1-是
is_anonymous anonymous_flag tinyint 0 是否允许匿名:0-否,1-是
is_readonly readonly_flag tinyint 0 是否只读:0-否,1-是
is_editable editable tinyint 1 是否可编辑:0-否,1-是
is_removable removable tinyint 1 是否可移除:0-否,1-是

示例:

visible tinyint not null default 1 comment '是否可见:0-否,1-是',
public_flag tinyint not null default 0 comment '是否公开:0-否,1-是',
readonly_flag tinyint not null default 0 comment '是否只读:0-否,1-是'

4. 表单 / 字段 / 页面配置类

旧字段名 新规范字段名 字段类型 默认值 注释
is_required required_flag tinyint 0 是否必填:0-否,1-是
is_nullable nullable_flag tinyint 1 是否允许为空:0-否,1-是
is_unique unique_flag tinyint 0 是否唯一:0-否,1-是
is_searchable searchable tinyint 0 是否可搜索:0-否,1-是
is_queryable queryable tinyint 0 是否可查询:0-否,1-是
is_exportable exportable tinyint 0 是否可导出:0-否,1-是
is_importable importable tinyint 0 是否可导入:0-否,1-是
is_printable printable tinyint 0 是否可打印:0-否,1-是
is_multiple multiple_flag tinyint 0 是否多选:0-否,1-是
is_single single_flag tinyint 1 是否单选:0-否,1-是

示例:

required_flag tinyint not null default 0 comment '是否必填:0-否,1-是',
searchable tinyint not null default 0 comment '是否可搜索:0-否,1-是',
exportable tinyint not null default 0 comment '是否可导出:0-否,1-是'

5. 内容 / 文章 / 新闻 / 商品类

旧字段名 新规范字段名 字段类型 默认值 注释
is_top top_flag tinyint 0 是否置顶:0-否,1-是
is_recommend recommend_flag tinyint 0 是否推荐:0-否,1-是
is_hot hot_flag tinyint 0 是否热门:0-否,1-是
is_new new_flag tinyint 0 是否新品/新内容:0-否,1-是
is_featured featured_flag tinyint 0 是否精选:0-否,1-是
is_published published tinyint 0 是否发布:0-否,1-是
is_draft draft_flag tinyint 0 是否草稿:0-否,1-是
is_original original_flag tinyint 1 是否原创:0-否,1-是
is_external external_flag tinyint 0 是否外部链接:0-否,1-是

示例:

top_flag tinyint not null default 0 comment '是否置顶:0-否,1-是',
recommend_flag tinyint not null default 0 comment '是否推荐:0-否,1-是',
published tinyint not null default 0 comment '是否发布:0-否,1-是'

6. 流程 / 审批 / 任务类

旧字段名 新规范字段名 字段类型 默认值 注释
is_submitted submitted tinyint 0 是否已提交:0-否,1-是
is_approved approved tinyint 0 是否已审批:0-否,1-是
is_rejected rejected tinyint 0 是否已驳回:0-否,1-是
is_finished finished tinyint 0 是否已完成:0-否,1-是
is_completed completed tinyint 0 是否已完成:0-否,1-是
is_canceled canceled tinyint 0 是否已取消:0-否,1-是
is_closed closed tinyint 0 是否已关闭:0-否,1-是
is_timeout timeout_flag tinyint 0 是否超时:0-否,1-是
is_urgent urgent_flag tinyint 0 是否紧急:0-否,1-是
is_overdue overdue tinyint 0 是否逾期:0-否,1-是

但这里要注意:流程类字段通常更推荐用 status,而不是一堆是否字段。

比如不推荐:

is_submitted
is_approved
is_rejected
is_completed

更推荐:

status tinyint not null default 0 comment '状态:0-待提交,1-审批中,2-已通过,3-已驳回,4-已取消'

只有少数独立标记才适合保留为 xxx_flag,比如:

urgent_flag tinyint not null default 0 comment '是否紧急:0-否,1-是',
overdue tinyint not null default 0 comment '是否逾期:0-否,1-是'

7. 登录 / 用户 / 安全类

旧字段名 新规范字段名 字段类型 默认值 注释
is_online online tinyint 0 是否在线:0-否,1-是
is_login login_flag tinyint 0 是否已登录:0-否,1-是
is_verified verified tinyint 0 是否已验证:0-否,1-是
is_certified certified tinyint 0 是否已认证:0-否,1-是
is_real_name real_name_flag tinyint 0 是否实名:0-否,1-是
is_password_expired password_expired tinyint 0 密码是否过期:0-否,1-是
is_force_change_password force_change_password tinyint 0 是否强制修改密码:0-否,1-是
is_mfa_enabled mfa_enabled tinyint 0 是否启用多因素认证:0-否,1-是
is_account_locked account_locked tinyint 0 账号是否锁定:0-否,1-是

示例:

online tinyint not null default 0 comment '是否在线:0-否,1-是',
verified tinyint not null default 0 comment '是否已验证:0-否,1-是',
account_locked tinyint not null default 0 comment '账号是否锁定:0-否,1-是'

8. 订单 / 支付 / 业务交易类

旧字段名 新规范字段名 字段类型 默认值 注释
is_paid paid tinyint 0 是否已支付:0-否,1-是
is_refunded refunded tinyint 0 是否已退款:0-否,1-是
is_shipped shipped tinyint 0 是否已发货:0-否,1-是
is_received received tinyint 0 是否已收货:0-否,1-是
is_invoiced invoiced tinyint 0 是否已开票:0-否,1-是
is_settled settled tinyint 0 是否已结算:0-否,1-是
is_confirmed confirmed tinyint 0 是否已确认:0-否,1-是
is_split split_flag tinyint 0 是否拆分:0-否,1-是
is_merge merge_flag tinyint 0 是否合并:0-否,1-是

同样,订单类更推荐主状态用 status,不要全靠布尔字段。

推荐:

pay_status tinyint not null default 0 comment '支付状态:0-未支付,1-已支付,2-已退款',
delivery_status tinyint not null default 0 comment '发货状态:0-未发货,1-已发货,2-已收货',
invoice_status tinyint not null default 0 comment '开票状态:0-未开票,1-已开票'

不建议只用:

paid
shipped
received
refunded

因为业务状态可能会越来越复杂。

9. 文件 / 附件 / 图片类

旧字段名 新规范字段名 字段类型 默认值 注释
is_image image_flag tinyint 0 是否图片:0-否,1-是
is_video video_flag tinyint 0 是否视频:0-否,1-是
is_audio audio_flag tinyint 0 是否音频:0-否,1-是
is_folder folder_flag tinyint 0 是否文件夹:0-否,1-是
is_encrypted encrypted tinyint 0 是否加密:0-否,1-是
is_compressed compressed tinyint 0 是否压缩:0-否,1-是
is_uploaded uploaded tinyint 0 是否已上传:0-否,1-是
is_downloaded downloaded tinyint 0 是否已下载:0-否,1-是

示例:

folder_flag tinyint not null default 0 comment '是否文件夹:0-否,1-是',
encrypted tinyint not null default 0 comment '是否加密:0-否,1-是',
uploaded tinyint not null default 0 comment '是否已上传:0-否,1-是'

10. 通知 / 消息 / 阅读类

旧字段名 新规范字段名 字段类型 默认值 注释
is_read read_flag tinyint 0 是否已读:0-否,1-是
is_unread unread_flag tinyint 1 是否未读:0-否,1-是
is_sent sent tinyint 0 是否已发送:0-否,1-是
is_pushed pushed tinyint 0 是否已推送:0-否,1-是
is_notified notified tinyint 0 是否已通知:0-否,1-是
is_reminded reminded tinyint 0 是否已提醒:0-否,1-是
is_confirmed confirmed tinyint 0 是否已确认:0-否,1-是

示例:

read_flag tinyint not null default 0 comment '是否已读:0-否,1-是',
sent tinyint not null default 0 comment '是否已发送:0-否,1-是',
pushed tinyint not null default 0 comment '是否已推送:0-否,1-是'

read 可能和语义、代码可读性冲突,所以更建议用:

read_flag

11. 时间状态类

旧字段名 新规范字段名 字段类型 默认值 注释
is_expired expired tinyint 0 是否过期:0-否,1-是
is_started started tinyint 0 是否已开始:0-否,1-是
is_ended ended tinyint 0 是否已结束:0-否,1-是
is_effective effective tinyint 1 是否生效:0-否,1-是
is_permanent permanent_flag tinyint 0 是否永久有效:0-否,1-是
is_temporary temporary_flag tinyint 0 是否临时:0-否,1-是
is_overdue overdue tinyint 0 是否逾期:0-否,1-是

但如果可以通过时间字段计算,就不一定要单独存布尔字段。

例如:

start_time datetime null comment '开始时间',
end_time datetime null comment '结束时间'

是否过期可以通过:

where end_time < now()

只有为了提升查询性能、固化业务结果、避免频繁计算时,才建议加:

expired tinyint not null default 0 comment '是否过期:0-否,1-是'

12. 组织 / 人员 / 部门类

旧字段名 新规范字段名 字段类型 默认值 注释
is_leader leader_flag tinyint 0 是否负责人:0-否,1-是
is_manager manager_flag tinyint 0 是否经理:0-否,1-是
is_owner owner_flag tinyint 0 是否负责人/所有者:0-否,1-是
is_member member_flag tinyint 1 是否成员:0-否,1-是
is_external_user external_user_flag tinyint 0 是否外部用户:0-否,1-是
is_main_dept main_dept_flag tinyint 0 是否主部门:0-否,1-是
is_charge_person charge_person_flag tinyint 0 是否负责人:0-否,1-是

示例:

leader_flag tinyint not null default 0 comment '是否负责人:0-否,1-是',
main_dept_flag tinyint not null default 0 comment '是否主部门:0-否,1-是',
external_user_flag tinyint not null default 0 comment '是否外部用户:0-否,1-是'

13. 设备 / 资产 / 运维类

旧字段名 新规范字段名 字段类型 默认值 注释
is_online online tinyint 0 是否在线:0-否,1-是
is_fault fault_flag tinyint 0 是否故障:0-否,1-是
is_alarm alarm_flag tinyint 0 是否告警:0-否,1-是
is_monitoring monitoring tinyint 1 是否监控中:0-否,1-是
is_managed managed tinyint 1 是否纳管:0-否,1-是
is_bound bound tinyint 0 是否已绑定:0-否,1-是
is_assigned assigned tinyint 0 是否已分配:0-否,1-是
is_recycled recycled tinyint 0 是否已回收:0-否,1-是

示例:

online tinyint not null default 0 comment '是否在线:0-否,1-是',
fault_flag tinyint not null default 0 comment '是否故障:0-否,1-是',
managed tinyint not null default 1 comment '是否纳管:0-否,1-是'

14. 推荐最终命名规则

规则 1:形容词类,直接去掉 is_

is_deleted   → deleted
is_enabled   → enabled
is_visible   → visible
is_locked    → locked
is_online    → online
is_expired   → expired
is_finished  → finished

规则 2:名词类、关键字类、容易冲突类,加 _flag

is_default   → default_flag
is_system    → system_flag
is_public    → public_flag
is_top       → top_flag
is_hot       → hot_flag
is_read      → read_flag

规则 3:复杂状态不要设计成多个 is_ 字段,改用 status

不推荐:

submitted tinyint
approved tinyint
rejected tinyint
completed tinyint

推荐:

status tinyint not null default 0 comment '状态:0-待提交,1-审批中,2-已通过,3-已驳回,4-已完成'

规则 4:字段类型统一

字段名 tinyint not null default 0 comment '是否xxx:0-否,1-是'

如果默认启用,则:

enabled tinyint not null default 1 comment '是否启用:0-否,1-是'

15. 最常用的一组建议直接固定下来

建议你们公司规范里优先固定这些:

deleted tinyint not null default 0 comment '是否删除:0-否,1-是',
enabled tinyint not null default 1 comment '是否启用:0-否,1-是',
visible tinyint not null default 1 comment '是否可见:0-否,1-是',
locked tinyint not null default 0 comment '是否锁定:0-否,1-是',
default_flag tinyint not null default 0 comment '是否默认:0-否,1-是',
system_flag tinyint not null default 0 comment '是否系统内置:0-否,1-是',
readonly_flag tinyint not null default 0 comment '是否只读:0-否,1-是',
required_flag tinyint not null default 0 comment '是否必填:0-否,1-是',
top_flag tinyint not null default 0 comment '是否置顶:0-否,1-是',
recommend_flag tinyint not null default 0 comment '是否推荐:0-否,1-是'

Java 实体对应:

private Boolean deleted;
private Boolean enabled;
private Boolean visible;
private Boolean locked;
private Boolean defaultFlag;
private Boolean systemFlag;
private Boolean readonlyFlag;
private Boolean requiredFlag;
private Boolean topFlag;
private Boolean recommendFlag;

最终建议:新表不要再建 is_ 字段。旧表如果已经有 is_deleted / is_enabled,可以暂时保留;新规范统一使用 deleted / enabled / xxx_flag。

 

 


是否统一加后缀 _flag ,更好些呢?

可以。下面按你前面确定的规范来:数据库字段尽量不使用 is_ 前缀,改成更简洁的 状态形容词字段xxx_flag 字段

推荐原则:

is_deleted   → deleted
is_enabled   → enabled
is_default   → default_flag
is_required  → required_flag

其中:

  • 能直接用形容词表达的,用简洁字段:deleted、enabled、visible、locked

  • 容易和关键字、业务名冲突的,用 _flag:default_flag、public_flag、system_flag

  • 数据库存储类型统一建议:tinyint not null default 0/1

  • 注释统一写:是否xxx:0-否,1-是

1. 通用基础类

旧字段名 新规范字段名 字段类型 默认值 注释
is_deleted deleted tinyint 0 是否删除:0-否,1-是
is_enabled enabled tinyint 1 是否启用:0-否,1-是
is_disabled disabled tinyint 0 是否禁用:0-否,1-是
is_active active tinyint 1 是否激活:0-否,1-是
is_valid valid tinyint 1 是否有效:0-否,1-是
is_invalid invalid_flag tinyint 0 是否无效:0-否,1-是
is_available available tinyint 1 是否可用:0-否,1-是
is_locked locked tinyint 0 是否锁定:0-否,1-是
is_frozen frozen tinyint 0 是否冻结:0-否,1-是

示例:

deleted tinyint not null default 0 comment '是否删除:0-否,1-是',
enabled tinyint not null default 1 comment '是否启用:0-否,1-是',
locked tinyint not null default 0 comment '是否锁定:0-否,1-是'

2. 系统内置 / 默认 / 管理类

旧字段名 新规范字段名 字段类型 默认值 注释
is_default default_flag tinyint 0 是否默认:0-否,1-是
is_system system_flag tinyint 0 是否系统内置:0-否,1-是
is_builtin builtin_flag tinyint 0 是否内置:0-否,1-是
is_admin admin_flag tinyint 0 是否管理员:0-否,1-是
is_super_admin super_admin_flag tinyint 0 是否超级管理员:0-否,1-是
is_master master_flag tinyint 0 是否主记录:0-否,1-是
is_primary primary_flag tinyint 0 是否主要:0-否,1-是
is_global global_flag tinyint 0 是否全局:0-否,1-是

default、system、primary 这类词单独作为字段名不够稳妥,所以建议加 _flag。

default_flag tinyint not null default 0 comment '是否默认:0-否,1-是',
system_flag tinyint not null default 0 comment '是否系统内置:0-否,1-是',
admin_flag tinyint not null default 0 comment '是否管理员:0-否,1-是'

3. 显示 / 权限 / 访问控制类

旧字段名 新规范字段名 字段类型 默认值 注释
is_visible visible tinyint 1 是否可见:0-否,1-是
is_hidden hidden tinyint 0 是否隐藏:0-否,1-是
is_public public_flag tinyint 0 是否公开:0-否,1-是
is_private private_flag tinyint 0 是否私有:0-否,1-是
is_open open_flag tinyint 0 是否开放:0-否,1-是
is_anonymous anonymous_flag tinyint 0 是否允许匿名:0-否,1-是
is_readonly readonly_flag tinyint 0 是否只读:0-否,1-是
is_editable editable tinyint 1 是否可编辑:0-否,1-是
is_removable removable tinyint 1 是否可移除:0-否,1-是

示例:

visible tinyint not null default 1 comment '是否可见:0-否,1-是',
public_flag tinyint not null default 0 comment '是否公开:0-否,1-是',
readonly_flag tinyint not null default 0 comment '是否只读:0-否,1-是'

4. 表单 / 字段 / 页面配置类

旧字段名 新规范字段名 字段类型 默认值 注释
is_required required_flag tinyint 0 是否必填:0-否,1-是
is_nullable nullable_flag tinyint 1 是否允许为空:0-否,1-是
is_unique unique_flag tinyint 0 是否唯一:0-否,1-是
is_searchable searchable tinyint 0 是否可搜索:0-否,1-是
is_queryable queryable tinyint 0 是否可查询:0-否,1-是
is_exportable exportable tinyint 0 是否可导出:0-否,1-是
is_importable importable tinyint 0 是否可导入:0-否,1-是
is_printable printable tinyint 0 是否可打印:0-否,1-是
is_multiple multiple_flag tinyint 0 是否多选:0-否,1-是
is_single single_flag tinyint 1 是否单选:0-否,1-是

示例:

required_flag tinyint not null default 0 comment '是否必填:0-否,1-是',
searchable tinyint not null default 0 comment '是否可搜索:0-否,1-是',
exportable tinyint not null default 0 comment '是否可导出:0-否,1-是'

5. 内容 / 文章 / 新闻 / 商品类

旧字段名 新规范字段名 字段类型 默认值 注释
is_top top_flag tinyint 0 是否置顶:0-否,1-是
is_recommend recommend_flag tinyint 0 是否推荐:0-否,1-是
is_hot hot_flag tinyint 0 是否热门:0-否,1-是
is_new new_flag tinyint 0 是否新品/新内容:0-否,1-是
is_featured featured_flag tinyint 0 是否精选:0-否,1-是
is_published published tinyint 0 是否发布:0-否,1-是
is_draft draft_flag tinyint 0 是否草稿:0-否,1-是
is_original original_flag tinyint 1 是否原创:0-否,1-是
is_external external_flag tinyint 0 是否外部链接:0-否,1-是

示例:

top_flag tinyint not null default 0 comment '是否置顶:0-否,1-是',
recommend_flag tinyint not null default 0 comment '是否推荐:0-否,1-是',
published tinyint not null default 0 comment '是否发布:0-否,1-是'

6. 流程 / 审批 / 任务类

旧字段名 新规范字段名 字段类型 默认值 注释
is_submitted submitted tinyint 0 是否已提交:0-否,1-是
is_approved approved tinyint 0 是否已审批:0-否,1-是
is_rejected rejected tinyint 0 是否已驳回:0-否,1-是
is_finished finished tinyint 0 是否已完成:0-否,1-是
is_completed completed tinyint 0 是否已完成:0-否,1-是
is_canceled canceled tinyint 0 是否已取消:0-否,1-是
is_closed closed tinyint 0 是否已关闭:0-否,1-是
is_timeout timeout_flag tinyint 0 是否超时:0-否,1-是
is_urgent urgent_flag tinyint 0 是否紧急:0-否,1-是
is_overdue overdue tinyint 0 是否逾期:0-否,1-是

但这里要注意:流程类字段通常更推荐用 status,而不是一堆是否字段。

比如不推荐:

is_submitted
is_approved
is_rejected
is_completed

更推荐:

status tinyint not null default 0 comment '状态:0-待提交,1-审批中,2-已通过,3-已驳回,4-已取消'

只有少数独立标记才适合保留为 xxx_flag,比如:

urgent_flag tinyint not null default 0 comment '是否紧急:0-否,1-是',
overdue tinyint not null default 0 comment '是否逾期:0-否,1-是'

7. 登录 / 用户 / 安全类

旧字段名 新规范字段名 字段类型 默认值 注释
is_online online tinyint 0 是否在线:0-否,1-是
is_login login_flag tinyint 0 是否已登录:0-否,1-是
is_verified verified tinyint 0 是否已验证:0-否,1-是
is_certified certified tinyint 0 是否已认证:0-否,1-是
is_real_name real_name_flag tinyint 0 是否实名:0-否,1-是
is_password_expired password_expired tinyint 0 密码是否过期:0-否,1-是
is_force_change_password force_change_password tinyint 0 是否强制修改密码:0-否,1-是
is_mfa_enabled mfa_enabled tinyint 0 是否启用多因素认证:0-否,1-是
is_account_locked account_locked tinyint 0 账号是否锁定:0-否,1-是

示例:

online tinyint not null default 0 comment '是否在线:0-否,1-是',
verified tinyint not null default 0 comment '是否已验证:0-否,1-是',
account_locked tinyint not null default 0 comment '账号是否锁定:0-否,1-是'

8. 订单 / 支付 / 业务交易类

旧字段名 新规范字段名 字段类型 默认值 注释
is_paid paid tinyint 0 是否已支付:0-否,1-是
is_refunded refunded tinyint 0 是否已退款:0-否,1-是
is_shipped shipped tinyint 0 是否已发货:0-否,1-是
is_received received tinyint 0 是否已收货:0-否,1-是
is_invoiced invoiced tinyint 0 是否已开票:0-否,1-是
is_settled settled tinyint 0 是否已结算:0-否,1-是
is_confirmed confirmed tinyint 0 是否已确认:0-否,1-是
is_split split_flag tinyint 0 是否拆分:0-否,1-是
is_merge merge_flag tinyint 0 是否合并:0-否,1-是

同样,订单类更推荐主状态用 status,不要全靠布尔字段。

推荐:

pay_status tinyint not null default 0 comment '支付状态:0-未支付,1-已支付,2-已退款',
delivery_status tinyint not null default 0 comment '发货状态:0-未发货,1-已发货,2-已收货',
invoice_status tinyint not null default 0 comment '开票状态:0-未开票,1-已开票'

不建议只用:

paid
shipped
received
refunded

因为业务状态可能会越来越复杂。

9. 文件 / 附件 / 图片类

旧字段名 新规范字段名 字段类型 默认值 注释
is_image image_flag tinyint 0 是否图片:0-否,1-是
is_video video_flag tinyint 0 是否视频:0-否,1-是
is_audio audio_flag tinyint 0 是否音频:0-否,1-是
is_folder folder_flag tinyint 0 是否文件夹:0-否,1-是
is_encrypted encrypted tinyint 0 是否加密:0-否,1-是
is_compressed compressed tinyint 0 是否压缩:0-否,1-是
is_uploaded uploaded tinyint 0 是否已上传:0-否,1-是
is_downloaded downloaded tinyint 0 是否已下载:0-否,1-是

示例:

folder_flag tinyint not null default 0 comment '是否文件夹:0-否,1-是',
encrypted tinyint not null default 0 comment '是否加密:0-否,1-是',
uploaded tinyint not null default 0 comment '是否已上传:0-否,1-是'

10. 通知 / 消息 / 阅读类

旧字段名 新规范字段名 字段类型 默认值 注释
is_read read_flag tinyint 0 是否已读:0-否,1-是
is_unread unread_flag tinyint 1 是否未读:0-否,1-是
is_sent sent tinyint 0 是否已发送:0-否,1-是
is_pushed pushed tinyint 0 是否已推送:0-否,1-是
is_notified notified tinyint 0 是否已通知:0-否,1-是
is_reminded reminded tinyint 0 是否已提醒:0-否,1-是
is_confirmed confirmed tinyint 0 是否已确认:0-否,1-是

示例:

read_flag tinyint not null default 0 comment '是否已读:0-否,1-是',
sent tinyint not null default 0 comment '是否已发送:0-否,1-是',
pushed tinyint not null default 0 comment '是否已推送:0-否,1-是'

read 可能和语义、代码可读性冲突,所以更建议用:

read_flag

11. 时间状态类

旧字段名 新规范字段名 字段类型 默认值 注释
is_expired expired tinyint 0 是否过期:0-否,1-是
is_started started tinyint 0 是否已开始:0-否,1-是
is_ended ended tinyint 0 是否已结束:0-否,1-是
is_effective effective tinyint 1 是否生效:0-否,1-是
is_permanent permanent_flag tinyint 0 是否永久有效:0-否,1-是
is_temporary temporary_flag tinyint 0 是否临时:0-否,1-是
is_overdue overdue tinyint 0 是否逾期:0-否,1-是

但如果可以通过时间字段计算,就不一定要单独存布尔字段。

例如:

start_time datetime null comment '开始时间',
end_time datetime null comment '结束时间'

是否过期可以通过:

where end_time < now()

只有为了提升查询性能、固化业务结果、避免频繁计算时,才建议加:

expired tinyint not null default 0 comment '是否过期:0-否,1-是'

12. 组织 / 人员 / 部门类

旧字段名 新规范字段名 字段类型 默认值 注释
is_leader leader_flag tinyint 0 是否负责人:0-否,1-是
is_manager manager_flag tinyint 0 是否经理:0-否,1-是
is_owner owner_flag tinyint 0 是否负责人/所有者:0-否,1-是
is_member member_flag tinyint 1 是否成员:0-否,1-是
is_external_user external_user_flag tinyint 0 是否外部用户:0-否,1-是
is_main_dept main_dept_flag tinyint 0 是否主部门:0-否,1-是
is_charge_person charge_person_flag tinyint 0 是否负责人:0-否,1-是

示例:

leader_flag tinyint not null default 0 comment '是否负责人:0-否,1-是',
main_dept_flag tinyint not null default 0 comment '是否主部门:0-否,1-是',
external_user_flag tinyint not null default 0 comment '是否外部用户:0-否,1-是'

13. 设备 / 资产 / 运维类

旧字段名 新规范字段名 字段类型 默认值 注释
is_online online tinyint 0 是否在线:0-否,1-是
is_fault fault_flag tinyint 0 是否故障:0-否,1-是
is_alarm alarm_flag tinyint 0 是否告警:0-否,1-是
is_monitoring monitoring tinyint 1 是否监控中:0-否,1-是
is_managed managed tinyint 1 是否纳管:0-否,1-是
is_bound bound tinyint 0 是否已绑定:0-否,1-是
is_assigned assigned tinyint 0 是否已分配:0-否,1-是
is_recycled recycled tinyint 0 是否已回收:0-否,1-是

示例:

online tinyint not null default 0 comment '是否在线:0-否,1-是',
fault_flag tinyint not null default 0 comment '是否故障:0-否,1-是',
managed tinyint not null default 1 comment '是否纳管:0-否,1-是'

14. 推荐最终命名规则

规则 1:形容词类,直接去掉 is_

is_deleted   → deleted
is_enabled   → enabled
is_visible   → visible
is_locked    → locked
is_online    → online
is_expired   → expired
is_finished  → finished

规则 2:名词类、关键字类、容易冲突类,加 _flag

is_default   → default_flag
is_system    → system_flag
is_public    → public_flag
is_top       → top_flag
is_hot       → hot_flag
is_read      → read_flag

规则 3:复杂状态不要设计成多个 is_ 字段,改用 status

不推荐:

submitted tinyint
approved tinyint
rejected tinyint
completed tinyint

推荐:

status tinyint not null default 0 comment '状态:0-待提交,1-审批中,2-已通过,3-已驳回,4-已完成'

规则 4:字段类型统一

字段名 tinyint not null default 0 comment '是否xxx:0-否,1-是'

如果默认启用,则:

enabled tinyint not null default 1 comment '是否启用:0-否,1-是'

15. 最常用的一组建议直接固定下来

建议你们公司规范里优先固定这些:

deleted tinyint not null default 0 comment '是否删除:0-否,1-是',
enabled tinyint not null default 1 comment '是否启用:0-否,1-是',
visible tinyint not null default 1 comment '是否可见:0-否,1-是',
locked tinyint not null default 0 comment '是否锁定:0-否,1-是',
default_flag tinyint not null default 0 comment '是否默认:0-否,1-是',
system_flag tinyint not null default 0 comment '是否系统内置:0-否,1-是',
readonly_flag tinyint not null default 0 comment '是否只读:0-否,1-是',
required_flag tinyint not null default 0 comment '是否必填:0-否,1-是',
top_flag tinyint not null default 0 comment '是否置顶:0-否,1-是',
recommend_flag tinyint not null default 0 comment '是否推荐:0-否,1-是'

Java 实体对应:

private Boolean deleted;
private Boolean enabled;
private Boolean visible;
private Boolean locked;
private Boolean defaultFlag;
private Boolean systemFlag;
private Boolean readonlyFlag;
private Boolean requiredFlag;
private Boolean topFlag;
private Boolean recommendFlag;

最终建议:新表不要再建 is_ 字段。旧表如果已经有 is_deleted / is_enabled,可以暂时保留;新规范统一使用 deleted / enabled / xxx_flag。