我正在嘗試制作簡單的 spring boot api 并自動生成表。但是當我呼叫 api 時,我得到一個表不存在的錯誤?我的 application.properties
spring.datasource.username=root
spring.datasource.password=123
logging.level.org.springframework.security=TRACE
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.properties.hibernate.formate_sql=true
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
server.error.include-message=always```
uj5u.com熱心網友回復:
由于非嵌入式資料庫(MySQL),您的配置不會自動生成任何表。因此,您必須顯式配置 ddl-auto。
spring.jpa.hibernate.ddl-auto=update
要么
spring.jpa.hibernate.ddl-auto=create-drop
查看Spring Docs了解更多詳細資訊。
uj5u.com熱心網友回復:
使用 spring boot 自動生成表 1. 首先使用 @Entity 注釋設定您的 POJO 類。2. 使用下面的屬性和運行應用程式表將自動創建。
spring.datasource.url=jdbc:mysql://localhost:3306/Your DB name
spring.datasource.username= username
spring.datasource.password= password
spring.jpa.hibernate.ddl-auto=update
這四種配置足以自動創建表。
uj5u.com熱心網友回復:
要生成表,您需要在 application.properties 中實作這一行:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/YOURSCHEMA
spring.datasource.username=YOURUSER
spring.datasource.password= YOURPASSWORD
spring.datasource.driver-class-name =com.mysql.jdbc.Driver
spring.jpa.show-sql: true
您還需要添加一些依賴項來運行專案,例如連接到資料庫的連接器,例如我使用 MySqlConnector。如果您更改了此行并且不起作用,請通過回復此執行緒向我提供有關您想要做什么的更多資訊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/440617.html
