第一步創(chuàng)建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:
# 更新或者創(chuàng)建數(shù)據(jù)表結(jié)構(gòu)
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主配置文件,來到數(shù)據(jù)庫界面管理軟件。發(fā)現(xiàn)我們的"person"表 自動創(chuàng)建好了

圖片.png
記得給主鍵ID加上:@GeneratedValue(strategy = GenerationType.IDENTITY)