Skip to content

Commit 45da758

Browse files
committed
refactor(extension/crud): 重构删除接口,以解决批量删除时 URL 中 ID 列表过长问题
1 parent a871048 commit 45da758

File tree

4 files changed

+104
-11
lines changed

4 files changed

+104
-11
lines changed

continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/controller/AbstractBaseController.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
import top.continew.starter.extension.crud.handler.CrudApiHandler;
3131
import top.continew.starter.extension.crud.model.query.PageQuery;
3232
import top.continew.starter.extension.crud.model.query.SortQuery;
33-
import top.continew.starter.extension.crud.model.resp.BaseIdResp;
33+
import top.continew.starter.extension.crud.model.req.IdsReq;
34+
import top.continew.starter.extension.crud.model.resp.IdResp;
3435
import top.continew.starter.extension.crud.model.resp.BasePageResp;
3536
import top.continew.starter.extension.crud.service.BaseService;
3637
import top.continew.starter.extension.crud.validation.CrudValidationGroup;
@@ -123,8 +124,8 @@ public D get(@PathVariable("id") Long id) {
123124
@Operation(summary = "创建数据", description = "创建数据")
124125
@ResponseBody
125126
@PostMapping
126-
public BaseIdResp<Long> create(@Validated(CrudValidationGroup.Create.class) @RequestBody C req) {
127-
return new BaseIdResp<>(baseService.create(req));
127+
public IdResp<Long> create(@Validated(CrudValidationGroup.Create.class) @RequestBody C req) {
128+
return new IdResp<>(baseService.create(req));
128129
}
129130

130131
/**
@@ -145,15 +146,14 @@ public void update(@Validated(CrudValidationGroup.Update.class) @RequestBody C r
145146
/**
146147
* 删除
147148
*
148-
* @param ids ID 列表
149+
* @param req 删除参数
149150
*/
150151
@CrudApi(Api.DELETE)
151152
@Operation(summary = "删除数据", description = "删除数据")
152-
@Parameter(name = "ids", description = "ID 列表", example = "1,2", in = ParameterIn.PATH)
153153
@ResponseBody
154-
@DeleteMapping("/{ids}")
155-
public void delete(@PathVariable("ids") List<Long> ids) {
156-
baseService.delete(ids);
154+
@DeleteMapping
155+
public void delete(@Validated @RequestBody IdsReq req) {
156+
baseService.delete(req.getIds());
157157
}
158158

159159
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
* <p>
4+
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.gnu.org/licenses/lgpl.html
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.starter.extension.crud.model.req;
18+
19+
import io.swagger.v3.oas.annotations.media.Schema;
20+
import jakarta.validation.constraints.NotNull;
21+
22+
import java.io.Serializable;
23+
24+
/**
25+
* ID 请求参数
26+
*
27+
* @author Charles7c
28+
* @since 2.11.0
29+
*/
30+
public class IdReq implements Serializable {
31+
32+
/**
33+
* ID
34+
*/
35+
@Schema(description = "ID", example = "1")
36+
@NotNull(message = "ID 不能为空")
37+
private Long id;
38+
39+
public Long getId() {
40+
return id;
41+
}
42+
43+
public void setId(Long id) {
44+
this.id = id;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
* <p>
4+
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.gnu.org/licenses/lgpl.html
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.starter.extension.crud.model.req;
18+
19+
import io.swagger.v3.oas.annotations.media.Schema;
20+
import jakarta.validation.constraints.NotEmpty;
21+
22+
import java.io.Serializable;
23+
import java.util.List;
24+
25+
/**
26+
* ID 列表请求参数
27+
*
28+
* @author Charles7c
29+
* @since 2.11.0
30+
*/
31+
public class IdsReq implements Serializable {
32+
33+
/**
34+
* ID
35+
*/
36+
@Schema(description = "ID", example = "[1,2]")
37+
@NotEmpty(message = "ID 不能为空")
38+
private List<Long> ids;
39+
40+
public List<Long> getIds() {
41+
return ids;
42+
}
43+
44+
public void setIds(List<Long> ids) {
45+
this.ids = ids;
46+
}
47+
}

continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/resp/BaseIdResp.java renamed 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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @author Charles7c
2727
* @since 2.5.0
2828
*/
29-
public class BaseIdResp<T extends Serializable> implements Serializable {
29+
public class IdResp<T extends Serializable> implements Serializable {
3030

3131
/**
3232
* ID
@@ -42,10 +42,10 @@ public void setId(T id) {
4242
this.id = id;
4343
}
4444

45-
public BaseIdResp() {
45+
public IdResp() {
4646
}
4747

48-
public BaseIdResp(final T id) {
48+
public IdResp(final T id) {
4949
this.id = id;
5050
}
5151
}

0 commit comments

Comments
 (0)