refactor: 优化分组校验

This commit is contained in:
2023-05-07 19:51:14 +08:00
parent ccd3d96c07
commit 78a5d5ec7a
6 changed files with 53 additions and 20 deletions

View File

@@ -144,7 +144,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
@Operation(summary = "新增数据")
@ResponseBody
@PostMapping
public R<Long> add(@Validated(BaseRequest.Add.class) @RequestBody C request) {
public R<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C request) {
this.checkPermission("add");
Long id = baseService.add(request);
return R.ok("新增成功", id);
@@ -162,7 +162,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
@Operation(summary = "修改数据")
@ResponseBody
@PutMapping("/{id}")
public R update(@Validated(BaseRequest.Update.class) @RequestBody C request, @PathVariable Long id) {
public R update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody C request, @PathVariable Long id) {
this.checkPermission("update");
baseService.update(request, id);
return R.ok("修改成功");

View File

@@ -18,8 +18,6 @@ package top.charles7c.cnadmin.common.base;
import java.io.Serializable;
import javax.validation.groups.Default;
import lombok.Data;
/**
@@ -32,14 +30,4 @@ import lombok.Data;
public class BaseRequest implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 分组校验-创建
*/
public interface Add extends Default {}
/**
* 分组校验-修改
*/
public interface Update extends Default {}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.charles7c.cnadmin.common.base;
import javax.validation.groups.Default;
/**
* 分组校验
*
* @author Charles7c
* @since 2023/5/7 19:41
*/
public interface ValidateGroup extends Default {
/**
* 分组校验-增删改查
*/
interface Crud extends ValidateGroup {
/**
* 分组校验-创建
*/
interface Add extends Crud {}
/**
* 分组校验-修改
*/
interface Update extends Crud {}
}
}