mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-12-15 19:00:53 +08:00
feat(extension/crud)): 新增钩子方法,用于增强增、删、改方法
This commit is contained in:
@@ -16,6 +16,12 @@
|
|||||||
<description>ContiNew Starter 扩展模块 - CRUD(增删改查)</description>
|
<description>ContiNew Starter 扩展模块 - CRUD(增删改查)</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- Crane4j(一个基于注解的,用于完成一切 “根据 A 的 key 值拿到 B,再把 B 的属性映射到 A” 这类需求的字段填充框架) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.crane4j</groupId>
|
||||||
|
<artifactId>crane4j-spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-commons</artifactId>
|
<artifactId>spring-data-commons</artifactId>
|
||||||
@@ -44,11 +50,5 @@
|
|||||||
<groupId>top.charles7c.continew</groupId>
|
<groupId>top.charles7c.continew</groupId>
|
||||||
<artifactId>continew-starter-api-doc</artifactId>
|
<artifactId>continew-starter-api-doc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Crane4j(一个基于注解的,用于完成一切 “根据 A 的 key 值拿到 B,再把 B 的属性映射到 A” 这类需求的字段填充框架) -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.crane4j</groupId>
|
|
||||||
<artifactId>crane4j-spring-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -146,26 +146,31 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long add(C req) {
|
public Long add(C req) {
|
||||||
if (null == req) {
|
this.beforeAdd(req);
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
T entity = BeanUtil.copyProperties(req, entityClass);
|
T entity = BeanUtil.copyProperties(req, entityClass);
|
||||||
baseMapper.insert(entity);
|
baseMapper.insert(entity);
|
||||||
|
this.afterAdd(req, entity);
|
||||||
return entity.getId();
|
return entity.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(C req, Long id) {
|
public void update(C req, Long id) {
|
||||||
|
this.beforeUpdate(req, id);
|
||||||
T entity = this.getById(id);
|
T entity = this.getById(id);
|
||||||
BeanUtil.copyProperties(req, entity, CopyOptions.create().ignoreNullValue());
|
BeanUtil.copyProperties(req, entity, CopyOptions.create().ignoreNullValue());
|
||||||
baseMapper.updateById(entity);
|
baseMapper.updateById(entity);
|
||||||
|
this.afterUpdate(req, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(List<Long> ids) {
|
public void delete(List<Long> ids) {
|
||||||
|
this.beforeDelete(ids);
|
||||||
baseMapper.deleteBatchIds(ids);
|
baseMapper.deleteBatchIds(ids);
|
||||||
|
this.afterDelete(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -212,6 +217,57 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增前置处理
|
||||||
|
*
|
||||||
|
* @param req 创建信息
|
||||||
|
*/
|
||||||
|
protected void beforeAdd(C req) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改前置处理
|
||||||
|
*
|
||||||
|
* @param req 修改信息
|
||||||
|
* @param id ID
|
||||||
|
*/
|
||||||
|
protected void beforeUpdate(C req, Long id) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除前置处理
|
||||||
|
*
|
||||||
|
* @param ids ID 列表
|
||||||
|
*/
|
||||||
|
protected void beforeDelete(List<Long> ids) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增后置处理
|
||||||
|
*
|
||||||
|
* @param req 创建信息
|
||||||
|
* @param entity 实体信息
|
||||||
|
*/
|
||||||
|
protected void afterAdd(C req, T entity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改后置处理
|
||||||
|
*
|
||||||
|
* @param req 修改信息
|
||||||
|
* @param entity 实体信息
|
||||||
|
*/
|
||||||
|
protected void afterUpdate(C req, T entity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除后置处理
|
||||||
|
*
|
||||||
|
* @param ids ID 列表
|
||||||
|
*/
|
||||||
|
private void afterDelete(List<Long> ids) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前实体类型
|
* 获取当前实体类型
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user