jpa 默认生成sql语句_springboot-jpa自动创建数据库表
第一步創建springboot項目,jpa,mysql,
代碼如下:
application.yml
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/springboot_test
username: root
password: 514730
driver-class-name: com.mysql.jdbc.Driver
jpa:
hibernate:
# 更新或者創建數據表結構
ddl-auto: update
# 控制臺顯示SQL
show-sql: true
實體類
import javax.persistence.*;
@Entity
@Table(name = "person")
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(length =50,name = "name")
private String name;
private String email;
private String gender;
private String address;
}
運行springboot主配置文件,來到數據庫界面管理軟件。發現我們的"person"表 自動創建好了
圖片.png
記得給主鍵ID加上:@GeneratedValue(strategy = GenerationType.IDENTITY)
總結
以上是生活随笔為你收集整理的jpa 默认生成sql语句_springboot-jpa自动创建数据库表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 不是吓唬你:发胖会影响生育 这三点预兆要
- 下一篇: mysql 批量_mysql LOAD语