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中

相关推荐
一 乐1 小时前
点餐|智能点餐系统|基于java+ Springboot的动端的点餐系统小程序(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·小程序·论文
程序定小飞4 小时前
基于springboot的作业管理系统设计与实现
java·开发语言·spring boot·后端·spring
qq_12498707536 小时前
基于springboot+vue的物流管理系统的设计与实现(源码+论文+部署+安装)
java·spring boot·后端·毕业设计
刘一说8 小时前
深入理解 Spring Boot Actuator:构建可观测性与运维友好的应用
运维·spring boot·后端
郝开8 小时前
最终 2.x 系列版本)2 - 框架搭建:pom配置;多环境配置文件配置;多环境数据源配置;测试 / 生产多环境数据源配置
java·spring boot·后端
用户3777967210968 小时前
RabbitMQ Unacked 消息深度解析:机制、问题与解决方案
spring boot·rabbitmq
小雨的光10 小时前
QuickRedis
spring boot·redis
星光一影11 小时前
Spring Boot 3+Spring AI 打造旅游智能体!集成阿里云通义千问,多轮对话 + 搜索 + PDF 生成撑全流程
人工智能·spring boot·spring
一 乐14 小时前
医疗管理|医院医疗管理系统|基于springboot+vue医疗管理系统设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·医疗管理系统
华仔啊14 小时前
SpringBoot 2.x 和 3.x 的核心区别,这些变化你必须知道
java·spring boot·后端