SpringBoot 参数校验之分组+嵌套校验

定义分组类

public class ExaminationPaperGroup {
 
public interface generatingTestPaper {}

public interface papersSubmitt {}
}

嵌套注解:valid

@Valid
@NotEmpty(message = "参数不可以为空”)
private List<ExaminationPaperDtoList> list;

嵌套类

public class  ExaminationPaperDtoList{
@notnull(mesage = "ID不可以空",groups =ExaminationPaperGroup.papersubmitt.class,ExaminationPaperGroup.generatingtestPaper.clas)
private Long questionId;
}

controller 使用

@PostMapping("/aa")
    public JsonResult aa(  @RequestBody @Validated({ExaminationPaperGroup.papersubmitt.class,ExaminationPaperGroup.generatingtestPaper.clas}) InsureConfigureVO insureConfigureVo) {
        log.info("editData提交的insure参数是:" + insureConfigureVo);
        return editDataHandler.handler(insureConfigureVo);
    }

你可能感兴趣的:(springboot,spring,boot)