jpa 默认生成sql语句_springBoot+jpa根据实体类注解生成SQL文件

基于环境:springBoot1.5+jpa2.1

在springBoot配置文件application.properties中添加如下属性即可:

spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create

spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=db/base/create.sql

生成脚本,jpa需要设置如下两项:

javax.persistence.schema-generation.scripts.action

创建sql脚本的方式。包含create, drop, drop-and-create, none,默认为none。

javax.persistence.schema-generation.scripts.create-target

是否在启动时将任何模式生成到脚本中。将处理在启动时加载元数据的所有类的模式(即在持久性单元中指定的类)。包含create, drop, drop-and-create, none,默认为none。

In addition all properties in spring.jpa.properties.* are passed through as normal JPA properties (with the prefix stripped) when the local EntityManagerFactory is created.

故,可直接使用上面最开始的两条语句达到在springBoot启动时用jpa生成SQL脚本文档。

参考资料

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值