您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Springboot中要怎么自定义校验

2024/5/2 18:42:01发布56次查看
startwithvalidation.class
@documented@constraint(validatedby = startwithvalidator.class )@target({method, field})@retention(runtime)public @interface startwithvalidation {  string message() default 不是正确的性别取值范围;  string start() default _;  class<?>[] groups() default {};  class<? extends payload>[] payload() default {};  @target({method, field, annotation_type, constructor, parameter})  @retention(runtime)  @documented  @interface list {    startwithvalidation[] value();  }}
startwithvalidator.class
public class startwithvalidator implements constraintvalidator<startwithvalidation, string> {  private string start;  @override  public void initialize(startwithvalidation constraintannotation) {    start = constraintannotation.start();  }  @override  public boolean isvalid(string value, constraintvalidatorcontext context) {    if (!stringutils.isempty(value)) {      return value.startswith(start);    }    return true;  }}
运用
@startwithvalidation(message = param 'address' must be start with 'beijing'., start = beijing)public string address;
以上就是springboot中要怎么自定义校验的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product