spring boot配置初始sql:spring boot关于初始sql脚本的配置有以下几个:
-
spring.datasource.initialize=true # populate using data.sql
-
spring.datasource.schema= # a schema (DDL) script resource reference
-
spring.datasource.data= # a data (DML) script resource reference
-
spring.datasource.platform= # the platform to use in the schema resource (schema-${platform}.sql)
这里说下DDl和DML等:
DDL:数据库模式定义语言,关键字:create DML:数据操纵语言,关键字:Insert、delete、update DCL:数据库控制语言 ,关键字:grant、remove DQL:数据库查询语言,关键字:select
再对应上面的注释,很容易就知道如何配置初始化sql脚本了
spring.datasource.data=classpath:data.sql
在data.sql中指定要导入的初始化数据
关于spring-data-jpa的entity DDL自动create-drop,如果使用的是h2database这样的内存数据库,那么这个属性是自动设为true的:
spring.jpa.hibernate.ddl-auto= # defaults to create-drop for embedded dbs
如果你使用的不是内存数据库,那么必须手动配置这个项为true
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto = update