Spring JPA自动生成数据表

在暑期实习中,学习到了JPA自动生成数据表的方法,以下是方法的纪录:

spring:
  thymeleaf:
    mode: HTML5
  # 配置数据源
  datasource:
    url: jdbc:mysql://localhost:3306/community_management?serverTimezone=Asia/Shanghai&characterEnconding=utf-8
    driver-class-name: com.mysql.jdbc.Driver
    username: root
    password: xxxxx
  # JPA 的配置
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true

创建要转为表的类:

@Entity
@Table(name = "users")
public class User {
    @Id                    //主键
    @GeneratedValue        //自增
    private Long id;
    private String username;
    private String password;
    private String sex;
    private Integer age;
    private Integer phone;
    private String avatar;
    private String role;
    private String createTime;
    private String address;
    private String user_health;
    }

运行后通过mysql-front查看表的建立情况:
Spring JPA自动生成数据表_第1张图片
创建成功

你可能感兴趣的:(暑期实习,java,mysql,数据库,spring)