第一步创建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
网友评论