Spring Boot Orm 简明教程

Spring Boot ORM - Application.properties

Spring boot 从 application.properties 中读取应用程序以及与持久性相关的属性。在这里,我们还可以配置 Hibernate 或任何其他 ORM 框架特定属性。我们使用通用属性,以便无需更改太多代码即可在 ORM 之间切换。默认情况下,如果 POM.xml 中没有指定其他 ORM 库,则 spring boot 配置 hibernate 作为 ORM 提供程序。

src −> main −> resources * 目录下创建 *application.properties 并如以下所示进行更新。

application.properties

#datasource configurations
spring.datasource.url=jdbc:mysql://localhost:3306/tutorialspoint?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=root@123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# show SQL
spring.jpa.show-sql: true
# DDL generation
spring.jpa.generate-ddl=true

以下是 application.properties 的 key 属性的描述。

  1. spring.datasource −数据库特定属性,例如连接 URL、用户名、密码、驱动程序类等。

  2. spring.jpa −特定的 jpa 属性,例如显示 sql 以创建表等。