update - 更新 Controller 处理参数绑定校验问题

This commit is contained in:
wangli 2023-07-31 15:06:53 +08:00
parent b44e3f7cb2
commit 1736da01c8
4 changed files with 30 additions and 26 deletions

View File

@ -12,10 +12,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import static cn.azxo.framework.common.model.CommonResponse.success;
@Tag(name = "运维管理 - 字典分类")
@ -25,30 +27,30 @@ import static cn.azxo.framework.common.model.CommonResponse.success;
@Validated
public class CategoryController {
@Autowired
@Resource
private CategoryService categoryService;
@Operation(summary = "创建分类")
@PostMapping("/create")
public CommonResponse<String> create(@RequestBody CategoryCreateDTO dto) {
public CommonResponse<Boolean> create(@Validated @RequestBody CategoryCreateDTO dto) {
log.info("创建Category===>>>参数:{}", JSON.toJSONString(dto));
categoryService.createCategory(dto);
return success();
return success(true);
}
@Operation(summary = "更新分类")
@PutMapping("/update")
public CommonResponse<String> update(@RequestBody CategoryUpdateDTO dto) {
public CommonResponse<Boolean> update(@Validated @RequestBody CategoryUpdateDTO dto) {
log.info("更新Category===>>>参数:{}", JSON.toJSONString(dto));
categoryService.updateCategory(dto);
return success();
return success(true);
}
@Operation(summary = "分类列表")
@GetMapping("/list")
public CommonResponse<IPage<CategoryItemVO>> list(@RequestBody CategorySearchDTO dto) {
public CommonResponse<IPage<CategoryItemVO>> list(@Validated @RequestBody CategorySearchDTO dto) {
log.info("查询Category===>>>列表接口参数,{}", JSON.toJSONString(dto));
Page<CategoryItemVO> bpmCategory = categoryService.findCategory(dto);
return success(bpmCategory);
@ -56,7 +58,8 @@ public class CategoryController {
@Operation(summary = "更新分类状态")
@PutMapping("/state/update")
public CommonResponse<Boolean> updateState(@RequestParam Long id, @RequestParam Boolean state) {
public CommonResponse<Boolean> updateState(@NotBlank(message = "分类 ID 不能为空") @RequestParam Long id,
@NotBlank(message = "状态不能为空") @RequestParam Boolean state) {
log.info("更新状态Category===>>>参数,{}", JSON.toJSONString(id));
return success(categoryService.updateState(id, state));
}
@ -64,10 +67,10 @@ public class CategoryController {
@Operation(summary = "删除分类")
@DeleteMapping("/delete")
public CommonResponse<String> delete(@RequestParam Long id) {
public CommonResponse<Boolean> delete(@NotBlank(message = "分类 ID 不能为空") @RequestParam Long id) {
log.info("删除Category===>>>参数,{}", id);
categoryService.deleteCategory(id);
return success();
return success(true);
}

View File

@ -37,7 +37,7 @@ public class FormDefinitionController {
@Operation(summary = "更新表单定义内容")
@PutMapping("/update")
public CommonResponse<Boolean> updateFormDefinition(@RequestBody FormDefinitionUpdateDTO dto) {
public CommonResponse<Boolean> updateFormDefinition(@Validated @RequestBody FormDefinitionUpdateDTO dto) {
formDefinitionService.updateFormDefinition(dto);
return success(true);
}
@ -46,7 +46,7 @@ public class FormDefinitionController {
@Operation(summary = "通过表单模型 ID 获取表单定义内容")
@GetMapping("/get")
public CommonResponse<FormDefinitionVO> get(@NotBlank(message = "模型 ID 不能为空") @RequestParam String formModelId,
@RequestParam String tenantId) {
@NotBlank(message = "租户不能为空") @RequestParam String tenantId) {
return success(formDefinitionService.get(formModelId, tenantId));
}

View File

@ -29,9 +29,9 @@ public class FormInstanceController {
private FormInstanceService formInstanceService;
@PostMapping("/content/update")
public CommonResponse<Void> updateFormContent(@RequestBody FormContentUpdateDTO dto) {
public CommonResponse<Boolean> updateFormContent(@Validated @RequestBody FormContentUpdateDTO dto) {
formInstanceService.updateFormContent(dto);
return success();
return success(true);
}
}

View File

@ -37,36 +37,37 @@ public class FormModelController {
@Operation(summary = "表单模型分页")
@GetMapping("/page")
public CommonResponse<BpmPageResult<FormModelBaseVO>> page(@RequestBody BpmnModelSearchDTO dto) {
public CommonResponse<BpmPageResult<FormModelBaseVO>> page(@Validated @RequestBody BpmnModelSearchDTO dto) {
return success(formModelService.getModelPage(dto));
}
@Operation(summary = "创建表单模型")
@PostMapping("/create")
public CommonResponse<String> create(@RequestBody FormModelCreateDTO dto) {
public CommonResponse<String> create(@Validated @RequestBody FormModelCreateDTO dto) {
return success(formModelService.createFormModel(dto));
}
@Operation(summary = "修改表单模型")
@PutMapping("/update")
public CommonResponse<Void> update(@RequestBody FormModelUpdateDTO dto) {
public CommonResponse<Void> update(@Validated @RequestBody FormModelUpdateDTO dto) {
formModelService.updateFormModel(dto);
return success();
}
@Operation(summary = "通过表单模型 ID 删除表单模型")
@DeleteMapping("/delete")
public CommonResponse<Boolean> deleteById(@ApiParam(name = "表单模型 ID") @NotBlank(message = "表单模型 ID 不能为空") @RequestParam String formModelId,
@RequestParam(required = false) String tenantId) {
public CommonResponse<Boolean> deleteById(
@ApiParam(name = "表单模型 ID") @NotBlank(message = "表单模型 ID 不能为空") @RequestParam String formModelId,
@RequestParam String tenantId) {
formModelService.deleteFormModelById(formModelId, tenantId);
return success(true);
}
@Operation(summary = "通过表单模型 KEY 删除表单模型")
@DeleteMapping("/deleteByKey")
public CommonResponse<Boolean> deleteByKey(@ApiParam(name = "表单模型 KEY") @NotBlank(message = "表单模型 KEY " +
"不能为空") @RequestParam String formModelKey,
@RequestParam(required = false) String tenantId) {
public CommonResponse<Boolean> deleteByKey(
@ApiParam(name = "表单模型 KEY") @NotBlank(message = "表单模型 KEY 不能为空") @RequestParam String formModelKey,
@NotBlank(message = "租户不能为空") @RequestParam String tenantId) {
formModelService.deployFormModelByKey(formModelKey, tenantId);
return success(true);
}
@ -74,28 +75,28 @@ public class FormModelController {
@Operation(summary = "获取指定表单模型 ID 的内容")
@GetMapping("/get")
public CommonResponse<FormModelBaseVO> getById(@NotBlank(message = "表单模型 ID 不能为空") @RequestParam String formModelId,
@RequestParam String tenantId) {
@NotBlank(message = "租户不能为空") @RequestParam String tenantId) {
return success(formModelService.getById(formModelId, tenantId));
}
@Operation(summary = "获取指定表单模型 KEy 的内容")
@GetMapping("/getByKey")
public CommonResponse<FormModelBaseVO> getByKey(@NotBlank(message = "表单模型 KEY 不能为空") @RequestParam String formModelKey,
@RequestParam String tenantId) {
@NotBlank(message = "租户不能为空") @RequestParam String tenantId) {
return success(formModelService.getByKey(formModelKey, tenantId));
}
@Operation(summary = "通过表单模型 ID 发布")
@PostMapping("/deploy")
public CommonResponse<String> deployById(@NotBlank(message = "模型 ID 不能为空") @RequestParam String formModelId,
@RequestParam(required = false) String tenantId) {
@NotBlank(message = "租户不能为空") @RequestParam String tenantId) {
return success(formModelService.deployFormModelById(formModelId, tenantId));
}
@Operation(summary = "通过表单模型 KEY 发布")
@PostMapping("/deployByKey")
public CommonResponse<String> deployByKey(@NotBlank(message = "模型 KEY 不能为空") @RequestParam String formModelKey,
@RequestParam(required = false) String tenantId) {
@NotBlank(message = "租户不能为空") @RequestParam String tenantId) {
return success(formModelService.deployFormModelByKey(formModelKey, tenantId));
}