Loading...
Loading...
Proxy2.0 数据库设计与操作规范:表设计命名、字段类型、索引规则、DO 对象、Mapper 接口、 SQL 安全、性能优化、MyBatis Plus 使用。Use when: (1) Creating database tables or SQL, (2) Writing DO classes, (3) Creating Mapper interfaces, (4) Reviewing database code, (5) Optimizing queries, (6) Working with MyBatis Plus.
npx skill4agent add kevinqpeng/proxy-skills proxy-backend-database| 对象 | 规则 | 示例 |
|---|---|---|
| 表名 | | |
| 关联表 | | |
| 字段 | snake_case | |
| 主键 | | — |
| 外键 | | |
| 唯一索引 | | |
| 普通索引 | | |
id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键',
creator VARCHAR(64) DEFAULT '' COMMENT '创建者',
create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
updater VARCHAR(64) DEFAULT '' COMMENT '更新者',
update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
deleted BIT(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (id)tenant_id BIGINT NOT NULL COMMENT '租户编号'| 用途 | MySQL 类型 | 说明 |
|---|---|---|
| 主键 | | — |
| 金额 | | 单位:分 |
| 精确小数 | | 非金额 |
| 布尔 | | — |
| 枚举/状态 | | 对应 Java 枚举 code |
| 时间 | | 对应 |
| JSON | | 配合 |
deleteddeleted_time@TableName("{模块}_{实体}")
@KeySequence("{模块}_{实体}_seq")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class {Entity}DO extends BaseDO {
@TableId
private Long id;
// 业务字段...
}BaseDO@TableName@TableId@link@TableField(typeHandler = JacksonTypeHandler.class)@Mapper
public interface {Entity}Mapper extends BaseMapperX<{Entity}DO> {
default PageResult<{Entity}DO> selectPage({Entity}PageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<{Entity}DO>()
.likeIfPresent({Entity}DO::getName, reqVO.getName())
.eqIfPresent({Entity}DO::getStatus, reqVO.getStatus())
.betweenIfPresent({Entity}DO::getCreateTime, reqVO.getCreateTime())
.orderByDesc({Entity}DO::getId));
}
}BaseMapperX<T>BaseMapperxxxIfPresentorderByDesc(DO::getId)#{}${}tenant_idSELECT *LambdaQueryWrapper.select()insertBatchupdateBatchWHERE id > #{lastId} LIMIT n@Transactional(readOnly = true)CREATE TABLE {模块}_{实体} (
id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键',
name VARCHAR(100) NOT NULL DEFAULT '' COMMENT '名称',
status TINYINT NOT NULL DEFAULT 0 COMMENT '状态:0-开启,1-关闭',
creator VARCHAR(64) DEFAULT '' COMMENT '创建者',
create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
updater VARCHAR(64) DEFAULT '' COMMENT '更新者',
update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
deleted BIT(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
tenant_id BIGINT NOT NULL DEFAULT 0 COMMENT '租户编号',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='{实体中文名}表';