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中

相关推荐
unique_perfect8 小时前
vue2与springboot实现deepseek打印机聊天
spring boot·websocket·ai·vue2·deepseek
哈哈老师啊9 小时前
Springboot学生综合测评系统hxtne(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
java·数据库·spring boot
气π11 小时前
【JavaWeb】——(若依 + AI)-基础学习笔记
java·spring boot·笔记·学习·java-ee·mybatis·ruoyi
老华带你飞12 小时前
列车售票|基于springboot 列车售票系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·学习·spring
汝生淮南吾在北12 小时前
SpringBoot+Vue在线考试系统
vue.js·spring boot·后端·毕业设计·毕设
script.boy12 小时前
基于spring boot校园二手交易平台的设计与实现
java·spring boot·后端
猿与禅13 小时前
Spring Boot 4.0 完整核心特性及实践指南
java·spring boot·后端·spring·重大升级·springboot4.0
曲莫终14 小时前
SpringBoot使用AutoConfiguration自动配置Bean
spring boot
E***U94515 小时前
从新手到入门:如何判断自己是否真的学会了 Spring Boot
数据库·spring boot·后端
invicinble15 小时前
javase-异常体系
开发语言·spring boot