spring 如何创建和更新数据库?
How does spring create and update databases?
我看过这行代码
spring.jpa.hibernate.ddl-auto=none
在多个 spring 教程中。例如,我的问题是在生产场景中,我希望我的应用程序首次在客户端计算机上创建一个数据库,然后继续使用该数据库,而不是每次 运行 时都重新创建一个新数据库。我怎样才能做到这一点?上面的代码到底是什么意思?
为此,您无需执行任何操作。在 application.properties 文件中添加:
spring.datasource.url=jdbc:mysql://localhost:3306/db_name
spring.datasource.username=root
spring.datasource.password=password
剩下的由 JPA 处理。
有时我们可能需要 运行 我们自己的 sql 应用程序启动脚本,方法是使用 data.sql 或 schema.sql 文件。在这种情况下,我们必须通过在 application.properties 文件中添加以下内容来禁用 Hibernate 自动模式创建。
spring.jpa.hibernate.ddl-auto=none
我看过这行代码
spring.jpa.hibernate.ddl-auto=none
在多个 spring 教程中。例如,我的问题是在生产场景中,我希望我的应用程序首次在客户端计算机上创建一个数据库,然后继续使用该数据库,而不是每次 运行 时都重新创建一个新数据库。我怎样才能做到这一点?上面的代码到底是什么意思?
为此,您无需执行任何操作。在 application.properties 文件中添加:
spring.datasource.url=jdbc:mysql://localhost:3306/db_name
spring.datasource.username=root
spring.datasource.password=password
剩下的由 JPA 处理。
有时我们可能需要 运行 我们自己的 sql 应用程序启动脚本,方法是使用 data.sql 或 schema.sql 文件。在这种情况下,我们必须通过在 application.properties 文件中添加以下内容来禁用 Hibernate 自动模式创建。
spring.jpa.hibernate.ddl-auto=none