首页>代码>SpringBoot校验FluentValidator和Hibernate Validator框架整合实例>/springboot-fluentvalidator/src/main/java/com/simon/springbootfluentvalidator/dto/User.java
package com.simon.springbootfluentvalidator.dto;
import com.baidu.unbiz.fluentvalidator.annotation.FluentValidate;
import com.simon.springbootfluentvalidator.validator.SexValidator;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.time.LocalDate;
/**
* @author Simon
*/
@Data
public class User implements Serializable {
private Long id;
@NotBlank(message = "用户名不能为空")
@Length(min = 8, max = 20, message = "用户名长度必须在8-20个字符之间")
private String name;
@NotBlank(message = "手机号不能为空")
@Length(min = 11, max = 11, message = "请输入11位手机号码")
private String mobile;
/**
* 出生日期,格式为 yyyy-MM-dd,必须为过去的日期,非必须参数
*/
@NotNull(message = "出生日期不能为空")
@Past(message = "出生日期必须早于当前日期")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate birthDay;
/**
* 等级,整数,0-5之间,必须参数
*/
@NotNull(message = "用户等级不能为空")
@Min(value = 0, message = "用户等级最小为0")
@Max(value = 5, message = "用户等级最大为5")
@Digits(integer = 1, fraction = 0, message = "用户等级必须为整数")
private Integer level;
/**
* 注意:使用了自定义校验注解的属性,不能再配置
*
* @org.hibernate.validator.constraints.NotBlank(message = "性别不能为空")
* @javax.validation.constraints.NotBlank(message = "性别不能为空")
* <p>
* 但是可以配置
* @javax.validation.constraints.NotNull(message = "性别不能为空")
*/
@NotNull(message = "性别不能为空")
@FluentValidate({SexValidator.class})
private Integer sex;
}
最近浏览更多
TY0165 LV20
2024年6月17日
youwuzuichen LV11
2024年4月17日
WBelong LV8
2023年12月25日
VINCENT_CHEN94 LV8
2023年11月3日
微信网友_6206233028890624 LV2
2022年11月7日
微信网友_6202233948950528
2022年11月2日
暂无贡献等级
ftssyang LV8
2022年10月25日
zxc131313 LV12
2022年10月22日
xuanjinya
2022年10月19日
暂无贡献等级
best2018 LV46
2022年10月18日

最近下载
