package com.example.demo.domain;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* @author wuxk07
*/
@Entity//
public class Girl {
@Id
@GeneratedValue
private Integer id;
private String cupSize;
private Integer age;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCupSize() {
return cupSize;
}
public void setCupSize(String cupSize) {
this.cupSize = cupSize;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
application.properties:
#ddl-auto:create:表示每次执行程序都会创建一个新的表,如果之前有这个表,会将这个表给删掉。
#ddl-auto:update:如果没有这个表会创建新表,如果有这个表并且表中有数据,不会删除表中的数据。
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
运行后会在数据库生成新表
本文介绍了一个名为Girl的实体类,该类使用了JPA注解与数据库表进行映射,包括自增ID、杯型大小和年龄属性。通过配置application.properties文件中的spring.jpa.hibernate.ddl-auto为update,确保了每次程序运行时都会更新数据库表结构,但保留已有数据。
493

被折叠的 条评论
为什么被折叠?



