提交 73ab797c authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] id自增,自动生成时间

上级 f0fb307f
package com.tykj.base.aop;
import com.tykj.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.base.entity.BaseEntity))")
public void checkTimes(JoinPoint point) {
Object[] args = point.getArgs();
for (Object arg : args) {
if (arg instanceof BaseEntity){
BaseEntity entity = (BaseEntity) arg;
if (isNull(entity.getCreatedTime())){
entity.setCreatedTime(new Date());
}
entity.setUpdatedTime(new Date());
}
}
}
}
......@@ -59,6 +59,7 @@ public class CreateTableUtil {
" <class entity-name=\"" + tableVO.getModelName() + "\" table=\"" + tableVO.getModelName() + "\">\n";
xmlMapping += " <id name=\"id\" type=\"java.lang.Integer\" length=\"11\" unsaved-value=\"null\" >\n" +
" <generator class=\"identity\" />"+
" </id>";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论