基于SpringBoot的online_music_player_(创建项目_数据库设计)

128 阅读2分钟

携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第1天,点击查看活动详情 

写在前面

本系列博客记录博主写的一个web项目!

创建项目

因为我们的online-music-player项目是基于SpringBoot框架开发的,所以我们需要创建一个SpringBoot项目!

image-20220726115032421

image-20220726115505183

选择SpringBoot版本并初步导入依赖!

image-20220726120252271

image-20220726121723445

数据库的设计

image-20220726122546219

根据我们的演示我们可以得知我们需要创建onlinemusic数据库,其下有3张结果!

image-20220726123715300

  • 创建onlinemusic 数据库

    -- 创建onlinemusic数据库
     drop database if exists onlinemusic;
     create database if not exists onlinemusic character set utf8;
    -- 使用onlinemusic
    use onlinemusic;
    
  • 创建user用户表

    -- 创建user表
    drop table if exists user;
    create table user (
        id int primary key auto_increment, -- 设置自增主键 id 
        username varchar(20) not null, -- 用户名不能为空!
        password varchar(255) not null -- 这里密码不为空,长度255留有足够长度加密操作
    ); 
    
  • 创建music音乐列表

    -- 创建music表
    drop table if exists music;
    create table music(
        id int primary key auto_increment,
        title varchar(50) not null, -- 歌曲名称
        singer varchar(30) not null, -- 歌手
        time varchar(13) not null, -- 添加时间
        url varchar(1000) not null, -- 歌曲路径
        user_id int(11) not null 
    );
    
  • 创建lovemusic收藏音乐列表

    -- 创建lovemusic表
    drop table if exists lovemusic;
    create table lovemusic(
        id int primary key auto_increment,
        user_id int(11) not null, -- 用户id
        music_id int(11) not null -- 音乐id
    );
    

    onlinemusic数据库下的3张表创建成功后!

image-20220726132147784

3张表结构如下!

image-20220726132259078

整个db.sql文件

-- 创建onlinemusic数据库
 drop database if exists onlinemusic;
 create database if not exists onlinemusic character set utf8;
-- 使用onlinemusic
use onlinemusic;
-- 创建user表
drop table if exists user;
create table user (
    id int primary key auto_increment, -- 设置自增主键 id
    username varchar(20) not null, -- 用户名不能为空!
    password varchar(255) not null -- 这里密码不为空,长度255留有足够长度加密操作
);
-- 创建music表
drop table if exists music;
create table music(
    id int primary key auto_increment,
    title varchar(50) not null, -- 歌曲名称
    singer varchar(30) not null, -- 歌手
    time varchar(13) not null, -- 添加时间
    url varchar(1000) not null, -- 歌曲路径
    user_id int(11) not null
);
-- 创建lovemusic表
drop table if exists lovemusic;
create table lovemusic(
    id int primary key auto_increment,
    user_id int(11) not null, -- 用户id
    music_id int(11) not null -- 音乐id
);