Database Setup
You need to first install the MySQL database (you can also use other databases, but this tutorial uses MySQL as an example). If you're unfamiliar with the installation process, you can search for MySQL tutorials on platforms like Bilibili.
-
Create a
goframe
database with the character setutf8
. -
Run the following SQL to create the test data tables:
USE `goframe`;
/* Table structure for table `book` */
DROP TABLE IF EXISTS `book`;
CREATE TABLE `book` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
`name` VARCHAR(50) NOT NULL COMMENT 'Name',
`author` VARCHAR(30) NOT NULL COMMENT 'Author',
`price` DOUBLE NOT NULL COMMENT 'Price',
`publish_time` DATE COMMENT 'Publish Time',
PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
/* Data for the table `book` */
INSERT INTO `book`(`id`,`name`,`author`,`price`) VALUES
(1,'MySQL Database Mastery','Wang Feifei',59.8),
(2,'Design Patterns','Liu Wei',45),
(3,'Database Principles and Applications','Liu Liang',33),
(4,'Linux Driver Development: Getting Started and Practice','Zheng Qiang',69),
(5,'Linux Driver Development: Getting Started and Practice','Zheng Qiang',69),
(6,'Linux Driver Development: Getting Started and Practice','Zheng Qiang',69);
/* Table structure for table `dept` */
DROP TABLE IF EXISTS `dept`;
CREATE TABLE `dept` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
`pid` INT(10) UNSIGNED DEFAULT NULL COMMENT 'Parent Department ID',
`name` VARCHAR(30) DEFAULT NULL COMMENT 'Department Name',
`leader` VARCHAR(20) DEFAULT NULL COMMENT 'Department Leader',
`phone` VARCHAR(11) DEFAULT NULL COMMENT 'Contact Phone',
PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=108 DEFAULT CHARSET=utf8;
/* Data for the table `dept` */
INSERT INTO `dept`(`id`,`pid`,`name`,`leader`,`phone`) VALUES
(100,0,'Universal','Zhao Fangxu','10000000000'),
(101,100,'North China Region','Xu Si','10000000001'),
(102,100,'Northeast China Region','Gao Lian','10000000002'),
(103,100,'East China Region','Dou Le','10000000003'),
(104,100,'Central China Region','Ren Fei','10000000004'),
(105,100,'South China Region',NULL,NULL),
(106,100,'Northwest China Region','Hua Feng','10000000005'),
(107,100,'Southwest China Region','Hao Yi','10000000006');
/* Table structure for table `emp` */
DROP TABLE IF EXISTS `emp`;
CREATE TABLE `emp` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
`dept_id` INT(10) UNSIGNED NOT NULL COMMENT 'Department ID',
`name` VARCHAR(30) NOT NULL COMMENT 'Name',
`gender` TINYINT(1) DEFAULT NULL COMMENT 'Gender: 0=Male 1=Female',
`phone` VARCHAR(11) DEFAULT NULL COMMENT 'Contact Phone',
`email` VARCHAR(50) DEFAULT NULL COMMENT 'Email',
`avatar` VARCHAR(100) DEFAULT NULL COMMENT 'Avatar',
PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;
/* Data for the table `emp` */
INSERT INTO `emp`(`id`,`dept_id`,`name`,`gender`,`phone`,`email`) VALUES
(1,100,'Zhao Fangxu',0,'10000000000','[email protected]'),
(2,100,'Bi Youlong',0,'10000000007','[email protected]'),
(3,100,'Huang Boren',0,'10000000008','[email protected]'),
(4,101,'Xu Si',0,'10000000001','[email protected]'),
(5,101,'Xu San',0,'10000000009','[email protected]'),
(6,101,'Feng Baobao',1,'10000000010','[email protected]'),
(7,101,'Zhang Chulan',0,'10000000011','[email protected]'),
(8,102,'Gao Lian',0,'10000000002','[email protected]'),
(9,102,'Gao Erzhuang',1,'10000000012','[email protected]'),
(10,103,'Dou Le',0,'10000000003','[email protected]'),
(11,103,'Xiao Zi Zai',0,'10000000013','[email protected]'),
(12,104,'Ren Fei',0,'10000000004','[email protected]'),
(13,106,'Hua Feng',0,'10000000005','[email protected]'),
(14,107,'Hao Yi',0,'10000000006','[email protected]');
/* Table structure for table `hobby` */
DROP TABLE IF EXISTS `hobby`;
CREATE TABLE `hobby` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
`emp_id` INT UNSIGNED NOT NULL COMMENT 'EmpID',
`hobby` VARCHAR(50) COMMENT 'Hobby',
PRIMARY KEY (`id`)
) ENGINE=INNODB CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO `hobby` (`id`, `emp_id`, `hobby`) VALUES
(1, 6, 'Burying people'),
(2, 4, 'Admiring beautiful women'),
(3, 7, 'Walking birds under the moon');
/* Table structure for table `user` */
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
`username` VARCHAR(20) NOT NULL COMMENT 'Username',
`nickname` VARCHAR(30) COMMENT 'Nickname',
`password` VARCHAR(32) COMMENT 'Password',
`avatar` VARCHAR(100) COMMENT 'Avatar',
`created_at` DATETIME COMMENT 'Creation Time',
PRIMARY KEY (`id`)
) ENGINE=INNODB CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO
`user` (`id`, `username`, `nickname`, `password`, `avatar`, `created_at`) VALUES
(1, 'libai', 'Li Bai', '123456', '', '2023-10-08 16:57:24'),
(2, 'dufu', 'Du Fu', '123456', '', '2023-10-08 16:57:24'),
(3, 'baijuyi', 'Bai Juyi', '123456', '', '2023-10-08 16:57:24');