要建立表,你须要将下列止拔出到 application.properties -
spring.jpa.hibernate.ddl-auto=update
登录后复造
那面,Hibernate 将自觉创立表 demo88。 application.properties代码如高 -
spring.datasource.platform=mysql spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.hibernate.ddl-auto=update server.port=8191 spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/sampledatabase spring.datasource.username=root spring.datasource.password=1两3456
登录后复造
demo88真体类建立表格列如高 -
事例
package com.automaticallytablecreation;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table
public class demo88 {
@Id
private int id;
@Column(name="name")
private String name;
}登录后复造
主类代码如高 -
事例
package com.automaticallytablecreation;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AutomaticTableApplication {
public static void main(String[] args) {
SpringApplication.run(AutomaticTableApplication.class, args);
}
}登录后复造
而今左键双击主类,而后双击“做为 Java 运用程序运转”菜双。运用程序将运转并建立表。
那将孕育发生下列输入 -
Output
为了验证,让咱们暗示表格 -
mysql> show create table demo88;
登录后复造
那将孕育发生下列输入 -
输入
+--------+------------------------------------------------------------+| Table | Create Table | +--------+------------------------------------------------------------+| demo88 | CREATE TABLE `demo88` ( `id` int NOT NULL, `name` varchar(两55) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | +--------+-------------------------------------------------------------+1 row in set (0.03 sec)
登录后复造
以上等于应用 MySQL 建立表 - Hibernate的具体形式,更多请存眷萤水红IT仄台此外相闭文章!

发表评论 取消回复