The Entry automatically generates the table SpringBootJpa
1. Add dependence
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
If so dependent on spring-data-jpa is deleted, otherwise an error can not find the bootstrap and the like will be
<!-- <dependency>-->
<!-- <groupId>org.springframework.data</groupId>-->
<!-- <artifactId>spring-data-jpa</artifactId>-->
<!-- <version>2.1.4.RELEASE</version>-->
<!-- </dependency>-->
2. Configure application.yml
Increase the allocation table is generated automatically Jpa
spring:
jpa: ##配置自动建表:updata:没有表新建,有表更新操作,控制台显示建表语句
hibernate:
ddl-auto: update
show-sql: true
3. Create Entity
Personal recommendations to create a foundation Entity, commonly used in the field to create a table
with mybatisplus, jackson, SnowFlake, lombok such as libraries, import their own
associated annotations Please inform yourself about
BaseEntry.java
@Data//省略setget方法
@MappedSuperclass //标注父类
@EntityListeners(AuditingEntityListener.class) //jpa数据监听
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) //忽略解析的字段
public abstract class BaseEntry implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@TableId
@ApiModelProperty(value = "唯一标识")
private String id = String.valueOf(SnowFlakeUtil.getFlowIdInstance().nextId());
@ApiModelProperty(value = "创建者")
@CreatedBy
private String createBy;
@CreatedDate
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "更新者")
@LastModifiedBy
private String updateBy;
@LastModifiedDate
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新时间")
private Date updateTime;
@ApiModelProperty(value = "删除标志 默认0")
@TableLogic
private Integer delFlag = CommonConstant.STATUS_NORMAL;
}
Business Entry, for reference only
/**
* tb_bussiness_up_record实体类
*
* @author
*
*/
@Data
@Entity
@Table(name = "tb_bussiness_up_record")
@TableName("tb_bussiness_up_record")
public class TbBussinessUpRecord extends BaseEntry {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "经销商")
private String bussinessId;
@ApiModelProperty(value = "审核时间")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private String auditTime;
}
Reproduced in: https: //www.jianshu.com/p/0a31ec81de77