mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-12 14:57:10 +08:00
refactor(extension/crud): 将新增操作由 ADD 改为创建操作 CREATE
This commit is contained in:
@@ -39,5 +39,5 @@ public @interface CrudRequestMapping {
|
||||
/**
|
||||
* API 列表
|
||||
*/
|
||||
Api[] api() default {Api.PAGE, Api.GET, Api.ADD, Api.UPDATE, Api.DELETE, Api.EXPORT};
|
||||
Api[] api() default {Api.PAGE, Api.GET, Api.CREATE, Api.UPDATE, Api.DELETE, Api.EXPORT};
|
||||
}
|
||||
|
@@ -114,17 +114,17 @@ public abstract class AbstractBaseController<S extends BaseService<L, D, Q, C>,
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* 创建
|
||||
*
|
||||
* @param req 创建参数
|
||||
* @return ID
|
||||
*/
|
||||
@CrudApi(Api.ADD)
|
||||
@Operation(summary = "新增数据", description = "新增数据")
|
||||
@CrudApi(Api.CREATE)
|
||||
@Operation(summary = "创建数据", description = "创建数据")
|
||||
@ResponseBody
|
||||
@PostMapping
|
||||
public BaseIdResp<Long> add(@Validated(CrudValidationGroup.Add.class) @RequestBody C req) {
|
||||
return new BaseIdResp<>(baseService.add(req));
|
||||
public BaseIdResp<Long> create(@Validated(CrudValidationGroup.Create.class) @RequestBody C req) {
|
||||
return new BaseIdResp<>(baseService.create(req));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -45,9 +45,9 @@ public enum Api {
|
||||
GET,
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* 创建
|
||||
*/
|
||||
ADD,
|
||||
CREATE,
|
||||
|
||||
/**
|
||||
* 修改
|
||||
|
@@ -88,12 +88,12 @@ public interface BaseService<L, D, Q, C> {
|
||||
List<LabelValueResp> listDict(Q query, SortQuery sortQuery);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* 创建
|
||||
*
|
||||
* @param req 创建参数
|
||||
* @return 自增 ID
|
||||
*/
|
||||
Long add(C req);
|
||||
Long create(C req);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
|
@@ -27,9 +27,9 @@ import jakarta.validation.groups.Default;
|
||||
public interface CrudValidationGroup extends Default {
|
||||
|
||||
/**
|
||||
* CRUD 分组校验-新增
|
||||
* CRUD 分组校验-创建
|
||||
*/
|
||||
interface Add extends CrudValidationGroup {}
|
||||
interface Create extends CrudValidationGroup {}
|
||||
|
||||
/**
|
||||
* CRUD 分组校验-修改
|
||||
|
@@ -133,11 +133,11 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdD
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long add(C req) {
|
||||
this.beforeAdd(req);
|
||||
public Long create(C req) {
|
||||
this.beforeCreate(req);
|
||||
T entity = BeanUtil.copyProperties(req, this.entityClass);
|
||||
mapper.insert(entity);
|
||||
this.afterAdd(req, entity);
|
||||
this.afterCreate(req, entity);
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdD
|
||||
*
|
||||
* @param req 创建信息
|
||||
*/
|
||||
protected void beforeAdd(C req) {
|
||||
protected void beforeCreate(C req) {
|
||||
/* 新增前置处理 */
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdD
|
||||
* @param req 创建信息
|
||||
* @param entity 实体信息
|
||||
*/
|
||||
protected void afterAdd(C req, T entity) {
|
||||
protected void afterCreate(C req, T entity) {
|
||||
/* 新增后置处理 */
|
||||
}
|
||||
|
||||
|
@@ -176,11 +176,11 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdD
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long add(C req) {
|
||||
this.beforeAdd(req);
|
||||
public Long create(C req) {
|
||||
this.beforeCreate(req);
|
||||
T entity = BeanUtil.copyProperties(req, super.getEntityClass());
|
||||
baseMapper.insert(entity);
|
||||
this.afterAdd(req, entity);
|
||||
this.afterCreate(req, entity);
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdD
|
||||
*
|
||||
* @param req 创建信息
|
||||
*/
|
||||
protected void beforeAdd(C req) {
|
||||
protected void beforeCreate(C req) {
|
||||
/* 新增前置处理 */
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdD
|
||||
* @param req 创建信息
|
||||
* @param entity 实体信息
|
||||
*/
|
||||
protected void afterAdd(C req, T entity) {
|
||||
protected void afterCreate(C req, T entity) {
|
||||
/* 新增后置处理 */
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user