AdminAuditableListener.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:SparkCommerce 作者:
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalCreatedField = auditable.getClass().getDeclaredField("dateCreated");
            Field temporalUpdatedField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalCreatedField, auditable);
            setAuditValueTemporal(temporalUpdatedField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号