All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kasinf.framework.rest.eneity.BaseEntity Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package com.kasinf.framework.rest.eneity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.kasinf.framework.rest.eneity.usertype.CollectionToStringUserType;
import com.kasinf.framework.rest.eneity.usertype.HashMapToStringUserType;
import com.kasinf.framework.rest.eneity.usertype.JsonToStringUserType;
import com.kasinf.framework.rest.eneity.usertype.ObjectSerializeUserType;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.util.Date;

/**
 * @param  主键类型
 * @author lkhsh
 * 通用Entity抽象类,提供了常用的4大字段。
 * 提供了4种常用的类型转换器。
 * 1、@Type(value="json")加在fastjson的JSONArray或JSONObject上,将json对象转换成字符串后存储到数据库
 * 2、@Type(value="map")加在Map上,可以通过@Parameter(name="keyType",value="xx.xx")定义键的类型,将map转换成json字符串后存到数据库
 * 3、@Type(value="collection")加在Collection类型上,将集合转换成字符串后存到数据库,参数有
 * 3.1 @Parameter(name="separator",value=",") 分隔符
 * 3.2 @Parameter(name="collectionType",value="java.util.ArrayList") 集合类型
 * 3.3 @Parameter(name="elementType",value="java.lang.String") 值的类型
 * 4、@Type(value="serialize")加在任意类型上,将对象序列化后存到数据库
 */
@Getter
@Setter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@TypeDefs({
        @TypeDef(name = "json", typeClass = JsonToStringUserType.class),
        @TypeDef(name = "map", typeClass = HashMapToStringUserType.class),
        @TypeDef(name = "collection", typeClass = CollectionToStringUserType.class),
        @TypeDef(name = "serialize", typeClass = ObjectSerializeUserType.class)
})
@Accessors(chain = true)
public abstract class BaseEntity implements AbstractEntity {

    @CreatedDate
    @Column(updatable = false)
    @JsonFormat
    private Date createTime;

    @LastModifiedDate
    @JsonFormat
    private Date modifyTime;

    @CreatedBy
    @Column(updatable = false)
    private String creator;

    @LastModifiedBy
    private String modifier;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy