美文网首页
Spring boot 启动时候运行DDL或者DML语句

Spring boot 启动时候运行DDL或者DML语句

作者: 黑曼巴yk | 来源:发表于2020-10-19 09:12 被阅读0次

步骤

数据源

 spring:
  datasource:
    username: root
    password: Hello12345
    url: jdbc:mysql://127.0.0.1:3306/demo
    driver-class-name: com.mysql.cj.jdbc.Driver
    schema:
      - classpath:student.sql
    initialization-mode: always

在resources文件下建立student.sql

CREATE TABLE `student` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
);

注意

需要设置 initialization-mode: always7

相关文章

网友评论

      本文标题:Spring boot 启动时候运行DDL或者DML语句

      本文链接:https://www.haomeiwen.com/subject/mfxhmktx.html