Spring Boot 3.1.9 + MariaDB 10.10.4 + OpenJDK17
在 application.properties 文件中添加如下内容:
spring.datasource.url = jdbc:mariadb://localhost:3306/vhmdb
spring.datasource.username = {account}
spring.datasource.password = {password}
spring.datasource.driver-class-name = org.mariadb.jdbc.Driver
# create, create-drop, validate, update, none
# Use "none" in production mode.
#spring.jpa.hibernate.ddl-auto = create
spring.jpa.generate-ddl = true
spring.jpa.show-sql = true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB103Dialect
-
spring.datasource.driver-class-name
可以不用配置,Spring Data JPA可以自动推断出driver。 -
spring.jpa.generate-ddl
与spring.jpa.hibernate.ddl-auto
都是用来从Entity生成数据库、数据表的配置项。如果需要从Entity生成数据库,只需要使用这两个配置中的一个即可。spring.jpa.generate-ddl
的值有两个:true 和 false。意思为:生成 或 不生成。spring.jpa.hibernate.ddl-auto
的值有 create, create-drop, validate, update, none. -
spring.jpa.properties.hibernate.dialect
使用此配置项来设置 dialect。MariaDB的dialect有点乱,目前还能使用的是 org.hibernate.dialect.MariaDB103Dialect。