欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springboot搭建我的第一个博客

程序员文章站 2024-03-04 20:48:54
...
CREATE DATABASE IF NOT EXISTS sob_blog_system CHAR SET utf8mb4 COLLATE utf8mb4_general_ci;

DROP TABLE IF EXISTS tb_user;
CREATE TABLE `sob_blog_system`.`tb_user` (
  `id` VARCHAR (20) NOT NULL COMMENT 'ID',
  `user_name` VARCHAR (32) NOT NULL COMMENT '用户名',
  `password` VARCHAR (32) NOT NULL,
  `email` VARCHAR (50),
  `sign` VARCHAR (100) COMMENT '签名',
  state VARCHAR (1) COMMENT '状态:0-删除,1-正常',
  reg_ip VARCHAR (32) NOT NULL COMMENT '注册ip',
  login_ip VARBINARY (32) NOT NULL COMMENT '登录ip',
  create_time DATETIME,
  update_time DATETIME,
  PRIMARY KEY (`id`)
) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;


DROP TABLE IF EXISTS tb_images;
CREATE TABLE `sob_blog_system`.`tb_images` (
  `id` VARCHAR (20) NOT NULL,
  `user_id` VARCHAR (20) NOT NULL,
  `url` VARCHAR (1024) NOT NULL,
  `state` VARCHAR (1) COMMENT '状态:0-删除,1-正常',
  `create_time` DATETIME NOT NULL,
  `update_time` DATETIME NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_user_images_on_user_id` (`user_id`),
  CONSTRAINT `fk_user_images_on_user_id` FOREIGN KEY (`user_id`) REFERENCES `tb_user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;

DROP TABLE IF EXISTS tb_categories;

CREATE TABLE `sob_blog_system`.`tb_categories` (
  `id` VARCHAR (20) NOT NULL,
  `name` VARCHAR (64) NOT NULL,
  `pinyin` VARCHAR (128) NOT NULL,
  `description` TEXT NOT NULL,
  `order` INT (11) NOT NULL,
  `state` VARCHAR (1) NOT NULL COMMENT '状态:0-删除,1-正常',
  `create_time` DATETIME NOT NULL,
  `update_time` DATETIME NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;


DROP TABLE IF EXISTS tb_article;
CREATE TABLE `sob_blog_system`.`tb_article` (
  `id` VARCHAR (20) NOT NULL,
  `title` VARCHAR (256) NOT NULL,
  `user_id` VARCHAR (20) NOT NULL,
  `category_id` VARCHAR (20) NOT NULL,
  `content` MEDIUMTEXT NOT NULL,
  `type` VARCHAR (1) NOT NULL COMMENT '类型:0-富文本,1-markdown',
  `state` VARCHAR (1) NOT NULL COMMENT '状态:0-已发布,1-草稿,2-删除',
  `summary` TEXT NOT NULL COMMENT '摘要',
  `labels` VARCHAR (128) NOT NULL COMMENT '',
  `view_count` INT (11) NOT NULL DEFAULT '0',
  `create_time` DATETIME NOT NULL,
  `update_time` DATETIME NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_user_article_on_user_id` (`user_id`),
  KEY `fk_category_article_on_article_id` (`category_id`),
  CONSTRAINT `fk_category_article_on_article_id` FOREIGN KEY (`category_id`) REFERENCES `tb_categories` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_user_article_on_user_id` FOREIGN KEY (`user_id`) REFERENCES `tb_user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;


DROP TABLE IF EXISTS tb_comment;
CREATE TABLE `tb_comment` (
  `id` VARCHAR (20) NOT NULL,
  `parent_content` TEXT,
  `article_id` VARCHAR (20) NOT NULL,
  `content` TEXT NOT NULL,
  `user_id` VARCHAR (20) NOT NULL,
  `user_avatar` VARCHAR (1024) DEFAULT NULL,
  `user_name` VARCHAR (32) DEFAULT NULL,
  `state` VARCHAR (1) NOT NULL COMMENT '0-删除,1-正常',
  `create_time` DATETIME NOT NULL,
  `update_time` DATETIME NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_user_comment_on_user_id` (`user_id`),
  KEY `fk_article_comment_on_article_id` (`article_id`),
  CONSTRAINT `fk_article_comment_on_article_id` FOREIGN KEY (`article_id`) REFERENCES `tb_article` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_user_comment_on_user_id` FOREIGN KEY (`user_id`) REFERENCES `tb_user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci DROP TABLE IF EXISTS tb_looper;

CREATE TABLE `sob_blog_system`.`tb_looper` (
  `id` VARCHAR (20) NOT NULL,
  `title` VARCHAR (128) NOT NULL,
  `order` INT (11) NOT NULL DEFAULT '0',
  `state` VARCHAR (1) NOT NULL COMMENT '状态:0-不可用,1-正常',
  `target_url` VARCHAR (1024) DEFAULT NULL,
  `image_url` VARCHAR (2014) NOT NULL,
  `create_time` DATETIME NOT NULL,
  `update_time` DATETIME NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;


DROP TABLE IF EXISTS tb_daily_view_count;
CREATE TABLE `sob_blog_system`.`tb_daily_view_count` (
  `id` VARCHAR (20) NOT NULL,
  `view_count` INT (11) NOT NULL DEFAULT '0',
  `create_time` DATETIME NOT NULL,
  `update_time` DATETIME NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;

DROP TABLE IF EXISTS tb_labels;

CREATE TABLE `sob_blog_system`.`tb_labels` (
  `id` VARCHAR (20) NOT NULL,
  `name` VARCHAR (32) NOT NULL,
  `count` INT NOT NULL DEFAULT '0',
  `create_time` DATETIME NOT NULL,
  `update_time` DATETIME NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;


DROP TABLE IF EXISTS tb_friends;
CREATE TABLE `sob_blog_system`.`tb_friends` (
  `id` VARCHAR (20) NOT NULL,
  `name` VARCHAR (32) NOT NULL,
  `logo` VARCHAR (1024) NOT NULL,
  `url` VARCHAR (1024) NOT NULL,
  `order` INT (11) NOT NULL,
  `state` VARCHAR (1) NOT NULL COMMENT '友链状态:0-不可用,1-正常',
  `create_time` DATETIME NOT NULL,
  `update_time` DATETIME NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;


DROP TABLE IF EXISTS tb_settings;
CREATE TABLE `sob_blog_system`.`tb_settings` (
  `id` VARCHAR (20) NOT NULL,
  `key` VARCHAR (32) NOT NULL,
  `value` VARCHAR (512) NOT NULL,
  `create_time` DATETIME NOT NULL,
  `update_time` DATETIME NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;

利用idea自带数据库脚本生成实体类

springboot搭建我的第一个博客

def generate(out, className, fields, table) {
  out.println "package $packageName"
  out.println ""
  out.println "import javax.persistence.Column;"
  out.println "import javax.persistence.Entity;"
  out.println "import javax.persistence.Id;"
  out.println "import javax.persistence.Table;"
  out.println "import java.util.Date;"
  out.println ""
  out.println "@Entity"
  out.println "@Table(name = \"" + table.getName() + "\")"
  out.println "public class $className {"
  out.println ""
  fields.each() {
    if("id".equals(it.name)){
      it.annos = "\aaa@qq.com"
    }else if ('order'.equals(Case.LOWER.apply(it.name))){
      it.annos = "\aaa@qq.com(name = \"`" + it.name +"`\" )"
    }else {
      it.annos = "\aaa@qq.com(name = \"" + it.name +"\" )"
    }
    if (it.annos != "") out.println "  ${it.annos}"
    out.println "\tprivate ${it.type} ${it.name};"
    out.println ""
  }
  out.println ""
  fields.each() {
    out.println ""
    out.println "\tpublic ${it.type} get${it.name.capitalize()}() {"
    out.println "\t\treturn ${it.name};"
    out.println "\t}"
    out.println ""
    out.println "\tpublic void set${it.name.capitalize()}(${it.type} ${it.name}) {"
    out.println "\t\tthis.${it.name} = ${it.name};"
    out.println "\t}"
    out.println ""
  }
  out.println "}"
}
相关标签: MySQL