Blog模块

设计表

文章表设计

create table if not exists article

(

    articleId     bigint  auto_increment comment '唯一标识' primary key,

    title         varchar(50)                  not null comment '文章标题',

    contentMarkdown text                         not null comment 'Markdown格式内容',

    contentHtml   text                         not null comment 'HTML格式内容',

    description   text                         not null comment '文章描述',

    cover         varchar(300)                 not null comment '封面',

    categoryId    bigint              not null comment '文章分类ID',

    authorId      bigint                       not null comment '作者ID',

    status        varchar(10) default 'public' not null comment '发布状态', -- public, private, draft

    createTime    datetime                     not null comment '发布时间',

    updateTime    datetime                     null comment '修改时间',

    isTop         int         default 0        null comment '是否置顶',

    foreign key (categoryId) references categories (categoryKey),

    foreign key (authorId) references user (id)

) comment '文章表';

分类表

-- 分类表

create table if not exists categories

(

    categoryKey   bigint auto_increment comment '唯一标识' primary key,

    categoryTitle varchar(50)            not null comment '分类名',

    description   varchar(255)           null comment '分类描述',

    icon          varchar(50)            null comment '分类图标',

    color         char(8) default '#fff' not null comment '分类颜色',

    pathName      varchar(50)            not null comment '分类路径名',

    constraint uk_categoryTitle unique (categoryTitle)

) comment '分类表';

标签树结构设计

create table if not exists tag

(

    tagId     bigint  auto_increment comment '唯一标识' primary key,

    title     varchar(20)               not null comment '标签名称',

    level     int     default 1         not null comment '标签层级',

    color     char(8) default '#ffffff' not null comment '标签颜色',

    parentId  bigint            null comment '父标签ID',

    constraint title unique (title),

    foreign key (parentId) references tag (tagId)

) comment '标签表';

文章标签关联表

create table if not exists article_tag

(

    articleId bigint not null comment '文章ID',

    tagId     bigint not null comment '标签ID',

    primary key (articleId, tagId),

    foreign key (articleId) references article (articleId),

    foreign key (tagId) references tag (tagId)

) comment '文章标签关联表';

使用MybatisX-Generator生成基础代码

业务逻辑

文章管理模块

核心功能:

文章增删改查(支持Markdown/HTML双内容存储)

分类关联管理(通过categoryId外键)

置顶文章(isTop字段控制)

状态管理(status字段控制:public/draft/private等)

关键点:

实现Markdown到HTML的自动转换(建议使用CommonMark-java)

内容存储策略:contentMarkdown为主存储,contentHtml作为缓存

状态转换控制:仅允许作者或管理员修改状态

分类管理模块

核心功能:

分类增删改查

分类路径名(pathName)生成(如"tech/web")

分类层级管理(当前表为单层,如需多级需补充parentId字段)

关键点:

分类名唯一性约束(已实现)

分类路径名生成规则设计(建议使用slug格式)

标签管理模块

核心功能:

标签树形结构管理(通过parentId和level字段)

标签颜色管理

标签关联文章(通过article_tag中间表)

关键点:

标签层级验证(确保父子节点关系合理性)

标签树形结构展示(前端需递归渲染)


项目分区导航:⬅️ 02-项目初始化 | 03-Blog模块 | ➡️ 04-Spring开发社交模块小记