springboot3+vue3融合项目实战-大事件文章管理系统-更新文章分类和增加文章分类优化-分组校验

因为我们之前在category实体类里面增加了@notnull注解,而之前新增文章分类模块新增文章是不需要id的,而id是由数据库自动分配的,这就导致不能新增文章了,所以我们要进行分组校验

思路如下:

我们更改category代码:

c 复制代码
public class Category {
    @NotNull(groups = Update.class)
    private Integer id;//主键ID
    @NotEmpty
    private String categoryName;//分类名称
    @NotEmpty
    private String categoryAlias;//分类别名
    private Integer createUser;//创建人ID
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;//创建时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;//更新时间

    //如果某个校验项目没有指定默认分组默认属于iDefault分组
    //分组之间可以继承,A extends B 那么B的所有属性都包含在A中
    public  interface Add extends Default {

    }

    public  interface Update extends Default{

    }

categoriycontroller中add方法修改

c 复制代码
@PostMapping
    public Result add(@RequestBody @Validated(Category.Add.class) Category category){
        categoryService.add(category);


        return Result.success("添加文章成功");
    }

update方法修改

c 复制代码
@PutMapping
    public Result update(@RequestBody @Validated(Category.Update.class) Category category){
        categoryService.update(category);
        return Result.success();
    }

注意的是
//如果某个校验项目没有指定默认分组默认属于iDefault分组
//分组之间可以继承,A extends B 那么B的所有属性都包含在A中

相关推荐
吴声子夜歌8 小时前
MongoDB 4.x——SpringBoot框架整合
数据库·spring boot·mongodb
snow@li8 小时前
Spring Boot:项目服务器完整部署教程(零基础可直接实操)
服务器·spring boot·后端
万亿少女的梦1689 小时前
基于Spring Boot、Java与MySQL的网络订餐系统设计与实现
java·spring boot·mysql·系统设计·网络订餐
鱟鲥鳚18 小时前
Spring Boot 集成 LangChain4j:从模型调用到 Tool Calling(Demo版)
java·spring boot
腾渊信息科技公司20 小时前
Spring Boot对接MES实战:视觉检测数据自动同步方案
java·人工智能·spring boot·后端·计算机视觉·ai·软件需求
隔窗听雨眠1 天前
Spring Boot在云原生时代的编程范式革新研究
spring boot·后端·云原生
其美杰布-富贵-李1 天前
Spring Boot 工程开发全流程说明
java·spring boot·后端
dear_bi_MyOnly1 天前
【SpringBoot配置文件】
java·spring boot·后端·学习·spring·java-ee·学习方法
其美杰布-富贵-李1 天前
Spring Boot 依赖注入说明文档
java·spring boot·python
流烟默1 天前
SpringBoot应用链路追踪 traceId 技术方案
spring boot·skywalking·traceid