项目完整地址:https://github.com/Pre4waist2m/blogSystem.git
1、user
2、blog
3、class(blog分类)
4、user_class(user对应的blog分类)
建表语句如下:
/*
MySQL Backup
Source Server Version: 8.0.15
Source Database: myblog
Date: 2019/3/5 18:06:25
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `blog`
-- ----------------------------
DROP TABLE IF EXISTS `blog`;
CREATE TABLE `blog` (
`blog_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`class_id` int(11) NOT NULL,
`blog_title` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`blog_content` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`blog_label` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`view_times` int(11) DEFAULT NULL,
`create_time` date DEFAULT NULL,
PRIMARY KEY (`blog_id`),
KEY `blog_ibfk_1` (`user_id`),
KEY `blog_ibfk_2` (`class_id`),
CONSTRAINT `blog_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `blog_ibfk_2` FOREIGN KEY (`class_id`) REFERENCES `class` (`class_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for `class`
-- ----------------------------
DROP TABLE IF EXISTS `class`;
CREATE TABLE `class` (
`class_id` int(11) NOT NULL,
`class_content` varchar(255) NOT NULL,
PRIMARY KEY (`class_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(20) NOT NULL,
`password` varchar(20) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Table structure for `user_class`
-- ----------------------------
DROP TABLE IF EXISTS `user_class`;
CREATE TABLE `user_class` (
`user_id` int(11) NOT NULL,
`class_id` int(11) NOT NULL,
`number` int(11) DEFAULT NULL,
PRIMARY KEY (`user_id`,`class_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records
-- ----------------------------
INSERT INTO `blog` VALUES ('8','1','3','妯″潡娴嬭瘯','甯屾湜鎴愬姛','鍔犳补',NULL,'2019-03-05'), ('9','1','3','qqq','鎴愮亴鐏岀亴鐏?,'iayou',NULL,NULL), ('10','2','4','鐨勬拻','鐖变笂鎿︽嫮','钀ㄩ暱鐨?,NULL,NULL), ('13','1','4','娴嬭瘯','缁堜簬鍐欏畬涓€涓簡','~',NULL,'2019-03-05'), ('14','1','4','娴嬭瘯','缁堜簬鍐欏畬涓€涓簡','~',NULL,'2019-03-05');
INSERT INTO `class` VALUES ('1','闅忕瑪'), ('2','鎬荤粨'), ('3','瀹炰範'), ('4','鍏朵粬');
INSERT INTO `user` VALUES ('1','machao1','1'), ('2','machao2','2'), ('3','machao','2'), ('4','success','1'), ('5','machao44','1'), ('6','bao','1');
INSERT INTO `user_class` VALUES ('1','3','2'), ('1','4','2'), ('2','4','1');