提交 82122474 authored 作者: 黄承天's avatar 黄承天

增加AOP机制 在调用CrudRepository的save前将会对待保存对象的CreateTime和UpdateTIme进行更新

上级 21c81f3f
package com.tykj.workflowcore.base.aop;
import com.tykj.workflowcore.base.entity.BaseEntity;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import java.util.Date;
import static java.util.Objects.isNull;
/**
* @author C
*/
@Aspect
@Component
public class EntityHandle {
@Before("execution(* org.springframework.data.repository.CrudRepository.save(..)) && args(com.tykj.workflowcore.base.entity.BaseEntity))")
public void checkTimes(JoinPoint point) {
Object[] args = point.getArgs();
for (Object arg : args) {
BaseEntity entity = (BaseEntity) arg;
if (isNull(entity.getCreatedTime())){
entity.setCreatedTime(new Date());
}
entity.setUpdatedTime(new Date());
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论