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

cn.org.atool.fluent.mybatis.base.IEntity Maven / Gradle / Ivy

package cn.org.atool.fluent.mybatis.base;

import java.io.Serializable;
import java.util.Map;

/**
 * IEntity 实体基类
 *
 * @author darui.wu
 */
public interface IEntity extends Serializable {
    /**
     * 返回实体主键
     *
     * @return 主键
     */
    default Serializable findPk() {
        return null;
    }

    /**
     * 数据库实体对应的Entity类名称, 在具体的XyzEntity类中定义为final, 防止返回匿名子类名称
     *
     * @return 实例类
     */
    default Class entityClass() {
        return this.getClass();
    }

    /**
     * 将实体对象转换为map对象, 不包括空字段
     *
     * @return map对象
     */
    default Map toEntityMap() {
        return this.toEntityMap(true);
    }

    /**
     * 将实体对象转换为map对象
     *
     * @param isNoN true:仅仅非空字段; false: 所有字段
     * @return map对象
     */
    default Map toEntityMap(boolean isNoN) {
        return IRefs.findEntityHelper(this.entityClass()).toEntityMap(this, isNoN);
    }

    /**
     * 将实体对象转换为数据库字段为key的map对象, 不包括空字段
     *
     * @return map对象
     */
    default Map toColumnMap() {
        return this.toColumnMap(true);
    }

    /**
     * 将实体对象转换为数据库字段为key的map对象
     *
     * @param isNoN true:仅仅非空字段; false: 所有字段
     * @return map对象
     */
    default Map toColumnMap(boolean isNoN) {
        return IRefs.findEntityHelper(this.entityClass()).toColumnMap(this, isNoN);
    }

    /**
     * 拷贝对象
     *
     * @param  实例类型
     * @return 实例对象
     */
    default  E copy() {
        return IRefs.findEntityHelper(this.entityClass()).copy(this);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy