Vue & SpringBoot 从零实现博客系统 (二)

本文系Vue & SpringBoot从零实现博客系统第二部分 数据库设计

数据库设计

  • 因为博客系统主要是文章,评论等等所以数据库也主要集中在这些方面

  • 但是说句实在话,我的数据库设计的并不好,可以看阿里巴巴Java开发手册

  • 同时我也没有使用外键,因为看到了上面的开发手册上不建议用我就没有用

  • 因为第一次搭建博客,缺乏经验,就没有用系统的工具画出数据库的E-R图,导致后来在重构了数据库的某些模块,如果你也和我一样想搭建一个博客,那么我希望你一定要想清楚需求,画好E-R图,设计好接口之后再开始编码
    在这里插入图片描述

推荐工具
  • 连接数据库可用DataGrip

  • 设计数据库可用 PowerDesigner等数据库建模工具

  • 当数据库的DDL写好以后,可以用Mybatis的逆向来生成domain的代码

一个小技巧
  • 由于我用的MySQL,可以在构建数据库的时候通过

    create_by datetime default CURRENT_TIMESTAMP not null comment '创建时间'这个语句来显示创建数据库的时间

    通过modified_by datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '修改日期'来显示修改时间

文章

文章有三个表

  • 一个是文章信息,包括文章的标题,总结,浏览次数,喜欢人数

    -- auto-generated definition
    create table article_info
    (
        id          bigint(40) auto_increment comment '主键'
            primary key,
        title       varchar(50)                        not null comment '文章标题,不能重复',
        summary     varchar(300)                       not null comment '文章简介,默认100个汉字以内',
        traffic     int(10)  default 0                 not null comment '文章访问量',
        create_by   datetime default CURRENT_TIMESTAMP not null comment '创建时间',
        modified_by datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '修改日期',
        love_num    int(10)  default 0                 not null comment '喜欢人数',
        constraint article_info_title_uindex
            unique (title)
    )
        comment '文章信息' charset = utf8;
    
  • 一个是文章内容,包括文章的markdown类型文件,同时和文章信息关联起来

    -- auto-generated definition
    create table article_content
    (
        id          bigint(40) auto_increment
            primary key,
        content     text                               not null,
        article_id  bigint(40)                         not null comment '对应文章ID',
        create_by   datetime default CURRENT_TIMESTAMP not null comment '创建时间',
        modified_by datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
        constraint article_content_article_id_uindex
            unique (article_id)
    )
        comment '文章内容' charset = utf8;
    
评论
  • 因为是多级评论,所以要除了评论内容,还要有父级评论,没有父级命令则该地方设为0

  • 同时因为有用户,评论表中还应有用户id

    -- auto-generated definition
    create table comment_info
    (
        id          bigint(40) auto_increment comment '主键'
            primary key,
        content     varchar(200) default ''                not null comment '留言/评论内容',
        create_by   datetime     default CURRENT_TIMESTAMP not null comment '创建日期',
        modified_by datetime     default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
        parent_id   bigint(40)   default 0                 not null comment '父类id',
        user_id     bigint(40)                             null comment '用户id'
    )
        comment '留言表' charset = utf8;
    
用户
  • 用户分为三类,ANY,USER,ADMIN,只要有IP登录,就会在该数据库进行写入,ip是唯一的

    --auto-generated definition
    create table sys_user
    (
    	id bigint(40) auto_increment comment '主键'
    		primary key,
    	name varchar(50) default '未注册' null comment '唯一值,昵称',
    	role varchar(30) not null comment '角色',
    	create_by datetime default CURRENT_TIMESTAMP not null,
    	modified_by datetime default CURRENT_TIMESTAMP null,
    	browser varchar(100) null comment '浏览器',
    	region varchar(50) default '未知' null comment '地址,ip与之对应',
    	connect varchar(50) default '未注册' null comment '联系方式',
    	ip varchar(50) null,
    	num bigint(40) default 1 null comment '用户浏览次数
    ',
    	constraint sys_user_ip_uindex
    		unique (ip)
    )
    comment '用户表';
    
  • 由于ADMIN只有一个,那就是我,所以我又另建了一个数据库专门存储我加密的密码

    sqlto-generated definition
    create table sys_me
    (
        id       bigint(40) auto_increment,
        name     varchar(50) null,
        password varchar(50) not null,
        u_id     bigint(40)  not null,
        constraint sys_me_id_uindex
            unique (id),
        constraint sys_me_name_uindex
            unique (name)
    );
    
    alter table sys_me
        add primary key (id);
    
分类
  • 分类也需要是多级的,所以要有父类id,同时也需要包括该分类所属的文章数量

    --sql-generated definition
    create table category_info
    (
        id          bigint(40) auto_increment
            primary key,
        name        varchar(20)                           not null comment '分类名称',
        number      tinyint(10) default 0                 not null comment '该分类下的文章数量',
        create_by   datetime    default CURRENT_TIMESTAMP not null comment '分类创建时间',
        modified_by datetime    default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '分类修改时间',
        parent_id   bigint(40)  default 0                 not null comment '父类id,默认为0'
    )
        comment '分类信息,name和subName可以重复' charset = utf8;
    
文章-用户
  • 这个主要是为了对应某篇文章和点赞人数的关系,防止同一用户多次点赞

    -- asqlenerated definition
    create table article_lover
    (
        id          bigint(40) auto_increment
            primary key,
        article_id  bigint(40)                         not null comment '对应文章id',
        user_id     bigint(40)                         not null comment '用户id',
        create_by   datetime default CURRENT_TIMESTAMP not null comment '创建时间',
        modified_by datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间'
    )
        comment '文章和点赞人数的关联表' charset = utf8;
    
文章-评论
  • 将文章评论和文章信息关联起来,多了一个is_effective是为了显示文章是否可见

    -- auto-generated definition
    create table article_comment
    (
        id           bigint(40) auto_increment
            primary key,
        article_id   bigint(40)                           not null comment '文章ID',
        comment_id   bigint(40)                           not null comment '对应的留言ID',
        create_by    datetime   default CURRENT_TIMESTAMP not null comment '创建时间',
        modified_by  datetime   default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
        is_effective tinyint(1) default 1                 not null comment '是否有效,默认为1有效,置0无效'
    )
        comment '文章评论关联表' charset = utf8;
    
文章-分类
  • 将文章和分类对应起来

    -- auto-generated definition
    create table article_category
    (
        id          bigint(40) auto_increment
            primary key,
        category_id bigint(40)                         not null comment '分类id',
        article_id  bigint(40)                         not null comment '文章id',
        create_by   datetime default CURRENT_TIMESTAMP not null comment '创建时间',
        modified_by datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间'
    )
        comment '文章和分类的关联表' charset = utf8;
    
日志
  • 最后一个是日志,记录ip的访问路径和时间

    -- auto-generated definition
    create table sys_log
    (
    	id bigint(40) auto_increment comment '主键'
    		primary key,
    	ip varchar(20) not null comment '访问者ip
    ',
    	create_by datetime default CURRENT_TIMESTAMP not null comment '操作时间',
    	operate_url varchar(120) default '' not null comment '操作的访问url',
    	operate_by varchar(100) default '' null comment '操作的客户端'
    )
    comment '访问日志' charset=utf8;
    

后记

至此,一个数据库算是设计完了,对于我来说有很多不足,但是当我发觉的时候,编码已经快完成了,数据库的设计根本米有考虑数据库的函数依赖和范式,回想起以前学的知识,到项目中还是蛮有用的。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
核心功能 文章/片/视频发布、喜欢、统计阅读次数。 文章标签tag功能、支持按tag分类 文章支持ueditor/markdown编辑器切换(后台配置) 评论功能,支持回复,支持表情。 第三方(微博、QQ)登录。 lucene实现的站内搜索。 响应式布局 支持用户订阅 先看效果 SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能) http://localhost:8080/admin/group/list SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能)SpringBoot开发非常美观的java博客系统(包含后台管理功能) 技术选型: JDK8 数据库MySQL 主框架 (Spring-bootSpring-data-jpa) 安全权限 Shiro 搜索工具 Lucene 缓存 Ehcache 视模板 Freemarker 其它 Jsoup、fastjson jQuery、Seajs Bootstrap 前端框架 UEditor/Markdown编辑器 font-Awesome 字体/标 准备工作(sql文件在项目里面) 安装 Jdk8 安装 Maven 准备 IDE (如果你不看源码,可以忽略下面的步骤,直接通过Maven编译war包:mvn clean package -DskipTests) IDE 需要配置的东西 编码方式设为UTF-8 配置Maven 设置Jdk8 关于这些配置,网上有一大把的资料,所以此处不再重复。 获取代码导入到IDE 下载代码 导入到IDE的时候请选择以Maven的方式导入 项目配置参考 系统配置手册 配置完毕 启动项目,在控制台看到Mblog加载完毕的信息后,表示启动成功 打开浏览器输入:http//localhost/mblog/ (此处仅是示例,具体具体端口因人而异),访问成功即部署完毕 后台管理的地址是 /admin, 如果你是管理员账号点导航栏的头像会看到"后台管理" 启动成功后,你应该去后台的系统配置里配置你的网站信息等。 常见问题总结 进入系统后, 菜单加载不出来, 那应该是你没有导 db_init.sql 点标签显示乱码, 请设置Tomcat的 URIEncoding 为 UTF-8 项目截 SpringBoot开发非常美观的java博客系统(包含后台管理功能) 转自:https://gitee.com/mtons/mblog SpringBoot开发非常美观的java博客系统(包含后台管理功能) 注意: 一、java main方式运行mblog-web下的BootApplication.java时抛出异常的解决方案 Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean. SpringBoot开发非常美观的java博客系统(包含后台管理功能) 注释掉后下面片的这段后,记得maven要重新reimport SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能) 否则maven依赖不生效还是会抛出以上的异常 、第三方登录点击后无响应,那是因为第三方开放平台回调的url失效导致,需要你去对应的第三方开放平台注册app后获取对应的oauth帐号 SpringBoot开发非常美观的java博客系统(包含后台管理功能) 三、idea以maven项目导入该项目后,发现没有maven的依赖包时,需要对每个maven module进行clear和install,并且注意maven的依赖顺序 SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能) 四、访问地址是http://localhost:8080 登录时,帐号,密码只要自己找个密码,然后md5下在更新到db中即可登录成功。 比如:zuidaima 111111,md5后密码是 3931MUEQD1939MQMLM4AISPVNE,md5的java类 SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值