• Hibernate:基础模型类


    根据业务建模型时,有一些字段基本每个表都是需要的,如下表:

    package com.company.jelly.model;
    
    import javax.persistence.EntityListeners;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.MappedSuperclass;
    import javax.persistence.Version;
    
    import org.springframework.data.annotation.CreatedDate;
    import org.springframework.data.annotation.LastModifiedDate;
    import org.springframework.data.jpa.domain.support.AuditingEntityListener;
    
    @MappedSuperclass
    @EntityListeners(AuditingEntityListener.class)
    public abstract class BaseModel {
    
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        protected Long id;
    
        @CreatedDate
        private Long createTimestamp;
    
        @LastModifiedDate
        private Long updateTimestamp;
    
        @Version
        private Long version;
    
        public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id = id;
        }
    
        public Long getCreateTimestamp() {
            return createTimestamp;
        }
    
        public void setCreateTimestamp(Long createTimestamp) {
            this.createTimestamp = createTimestamp;
        }
    
        public Long getUpdateTimestamp() {
            return updateTimestamp;
        }
    
        public void setUpdateTimestamp(Long updateTimestamp) {
            this.updateTimestamp = updateTimestamp;
        }
    
        public Long getVersion() {
            return version;
        }
    
        public void setVersion(Long version) {
            this.version = version;
        }
    
    }

     需要说明的是需要在SpringBoot启动类上面添加@EnableJpaAuditing注解

  • 相关阅读:
    Unity---游戏设计模式(6)之策略模式
    Unity---游戏设计模式(5)之桥接模式
    Unity---游戏设计模式(3)之单例模式
    ThinkPHP钩子和行为
    如何理解ThinkPHP框架里的依赖注入
    MySql读写分离实现
    PHP 微服务集群搭建
    详解MySQL的主从复制、读写分离、备份恢复
    索引差异
    nginx高可用
  • 原文地址:https://www.cnblogs.com/colin220/p/9490925.html
Copyright © 2020-2023  润新知