zoukankan      html  css  js  c++  java
  • 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注解

  • 相关阅读:
    2032 杨辉三角
    2023 求平均成绩
    幸运数
    扑克牌大小
    single-number
    合唱队
    Problem A: 【字符串】最长回文子串
    Problem A: 最大连续子序列
    数串
    02CSS3基本语法05
  • 原文地址:https://www.cnblogs.com/colin220/p/9490925.html
Copyright © 2011-2022 走看看