diff --git a/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/controller/AbstractBaseController.java b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/controller/AbstractBaseController.java index eb77c4cb..477edd7c 100644 --- a/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/controller/AbstractBaseController.java +++ b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/controller/AbstractBaseController.java @@ -30,7 +30,8 @@ import top.continew.starter.extension.crud.enums.Api; import top.continew.starter.extension.crud.handler.CrudApiHandler; import top.continew.starter.extension.crud.model.query.PageQuery; import top.continew.starter.extension.crud.model.query.SortQuery; -import top.continew.starter.extension.crud.model.resp.BaseIdResp; +import top.continew.starter.extension.crud.model.req.IdsReq; +import top.continew.starter.extension.crud.model.resp.IdResp; import top.continew.starter.extension.crud.model.resp.BasePageResp; import top.continew.starter.extension.crud.service.BaseService; import top.continew.starter.extension.crud.validation.CrudValidationGroup; @@ -123,8 +124,8 @@ public abstract class AbstractBaseController, @Operation(summary = "创建数据", description = "创建数据") @ResponseBody @PostMapping - public BaseIdResp create(@Validated(CrudValidationGroup.Create.class) @RequestBody C req) { - return new BaseIdResp<>(baseService.create(req)); + public IdResp create(@Validated(CrudValidationGroup.Create.class) @RequestBody C req) { + return new IdResp<>(baseService.create(req)); } /** @@ -145,15 +146,14 @@ public abstract class AbstractBaseController, /** * 删除 * - * @param ids ID 列表 + * @param req 删除参数 */ @CrudApi(Api.DELETE) @Operation(summary = "删除数据", description = "删除数据") - @Parameter(name = "ids", description = "ID 列表", example = "1,2", in = ParameterIn.PATH) @ResponseBody - @DeleteMapping("/{ids}") - public void delete(@PathVariable("ids") List ids) { - baseService.delete(ids); + @DeleteMapping + public void delete(@Validated @RequestBody IdsReq req) { + baseService.delete(req.getIds()); } /** diff --git a/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/req/IdReq.java b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/req/IdReq.java new file mode 100644 index 00000000..26d60ed6 --- /dev/null +++ b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/req/IdReq.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.starter.extension.crud.model.req; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; + +import java.io.Serializable; + +/** + * ID 请求参数 + * + * @author Charles7c + * @since 2.11.0 + */ +public class IdReq implements Serializable { + + /** + * ID + */ + @Schema(description = "ID", example = "1") + @NotNull(message = "ID 不能为空") + private Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } +} diff --git a/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/req/IdsReq.java b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/req/IdsReq.java new file mode 100644 index 00000000..886af450 --- /dev/null +++ b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/req/IdsReq.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.starter.extension.crud.model.req; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; + +import java.io.Serializable; +import java.util.List; + +/** + * ID 列表请求参数 + * + * @author Charles7c + * @since 2.11.0 + */ +public class IdsReq implements Serializable { + + /** + * ID + */ + @Schema(description = "ID", example = "[1,2]") + @NotEmpty(message = "ID 不能为空") + private List ids; + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } +} diff --git a/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/resp/BaseIdResp.java b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/resp/IdResp.java similarity index 88% rename from continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/resp/BaseIdResp.java rename to continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/resp/IdResp.java index ae9a9e8e..2a10b46f 100644 --- a/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/resp/BaseIdResp.java +++ b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/resp/IdResp.java @@ -26,7 +26,7 @@ import java.io.Serializable; * @author Charles7c * @since 2.5.0 */ -public class BaseIdResp implements Serializable { +public class IdResp implements Serializable { /** * ID @@ -42,10 +42,10 @@ public class BaseIdResp implements Serializable { this.id = id; } - public BaseIdResp() { + public IdResp() { } - public BaseIdResp(final T id) { + public IdResp(final T id) { this.id = id; } }