当前位置: 首页 > news >正文

广东省广州市有哪几个区seo培训机构排名

广东省广州市有哪几个区,seo培训机构排名,网站建设公司怎,东莞城乡住建局spring boot项目对参数进行校验时,比如非空校验,可以直接用validation包里面自带的注解。但是对于一些复杂的参数校验,自带的校验规则无法满足要求,此时需要我们自定义参数校验规则。自定义校验规则和自带的规则实现方式一样&…

spring boot项目对参数进行校验时,比如非空校验,可以直接用validation包里面自带的注解。但是对于一些复杂的参数校验,自带的校验规则无法满足要求,此时需要我们自定义参数校验规则。自定义校验规则和自带的规则实现方式一样,先自定义一个注解,然后指定校验类,在校验类里实现具体的校验规则。

下面以校验手机号为例,来实现自定义参数校验规则。

首先定义一个注解,直接照着NotNull注解定义即可。

@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
//这里的class就是实现具体校验规则的类
@Constraint(validatedBy = {MobileNoValidator.class})
public @interface MobileNo {String message() default "请输入正确的手机号";Class<?>[] groups() default {};Class<? extends Payload>[] payload() default {};}

然后定义实现具体校验规则的类,这个类要实现ConstraintValidator接口。

public class MobileNoValidator implements ConstraintValidator<MobileNo, String> {@Overridepublic boolean isValid(String value, ConstraintValidatorContext context) {if ((value == null)) {return false;}String regex = "^1\\d{10}$";Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);Matcher m = p.matcher(value);return m.matches();}
}

这样,很简单的两个类,就实现了自定义参数校验规则。当参数中加了MobileNo注解,如果输入的手机号不满足1打头的11位数字的规则,就会抛出异常信息。下面写个controller简单测试一下。

先定义一个vo。

public class UserVo {@NotNullprivate Long id;@NotNull@MobileNoprivate String mobileNo;public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getMobileNo() {return mobileNo;}public void setMobileNo(String mobileNo) {this.mobileNo = mobileNo;}
}

再定一个controller。

@RestController
public class UserController {@PostMapping(value = "/test")public String test(@Validated @RequestBody UserVo userVo) {return "success";}
}

启动项目,用postman测试一下。

首先输入符合要求的手机号,这时是能正常返回success。

然后输入一个不符合要求的手机号,会返回400错误码,错误信息如下。当然这里返回的错误信息比较不友好,实际项目中可以对参数校验异常统一拦截,返回需要的数据格式。


文章转载自:
http://dinncocragginess.ssfq.cn
http://dinncolongirostral.ssfq.cn
http://dinncounearned.ssfq.cn
http://dinncoallantois.ssfq.cn
http://dinncowagoner.ssfq.cn
http://dinncofalstaff.ssfq.cn
http://dinncochair.ssfq.cn
http://dinncomadwoman.ssfq.cn
http://dinncoundouble.ssfq.cn
http://dinncoirrecusable.ssfq.cn
http://dinncoserpentinize.ssfq.cn
http://dinncoconglobate.ssfq.cn
http://dinncoarcticologist.ssfq.cn
http://dinncosomali.ssfq.cn
http://dinncozygosperm.ssfq.cn
http://dinncointegral.ssfq.cn
http://dinncomathematic.ssfq.cn
http://dinncoparachute.ssfq.cn
http://dinncocommander.ssfq.cn
http://dinncodensely.ssfq.cn
http://dinncoruggedly.ssfq.cn
http://dinnconeurotropic.ssfq.cn
http://dinncoplagiocephalic.ssfq.cn
http://dinncobrut.ssfq.cn
http://dinncofakir.ssfq.cn
http://dinncogabbart.ssfq.cn
http://dinncoactorish.ssfq.cn
http://dinncochase.ssfq.cn
http://dinncogenteel.ssfq.cn
http://dinncosaprobe.ssfq.cn
http://dinncoplata.ssfq.cn
http://dinncoreptile.ssfq.cn
http://dinncorepealer.ssfq.cn
http://dinncohempy.ssfq.cn
http://dinncoanamorphism.ssfq.cn
http://dinncoangelical.ssfq.cn
http://dinncotiepin.ssfq.cn
http://dinncolooie.ssfq.cn
http://dinncopaediatric.ssfq.cn
http://dinncocensure.ssfq.cn
http://dinncorighteous.ssfq.cn
http://dinncoetc.ssfq.cn
http://dinncoconfederal.ssfq.cn
http://dinncoescape.ssfq.cn
http://dinncoapprehension.ssfq.cn
http://dinncohumdinger.ssfq.cn
http://dinncoorthopraxis.ssfq.cn
http://dinncomoonwalk.ssfq.cn
http://dinncoimmediate.ssfq.cn
http://dinncodonatism.ssfq.cn
http://dinncoquiverful.ssfq.cn
http://dinncomoneyman.ssfq.cn
http://dinncodeambulation.ssfq.cn
http://dinncodorsolateral.ssfq.cn
http://dinncospraddle.ssfq.cn
http://dinncofogging.ssfq.cn
http://dinncomisesteem.ssfq.cn
http://dinncoexemplify.ssfq.cn
http://dinncobraize.ssfq.cn
http://dinncodispend.ssfq.cn
http://dinncopurely.ssfq.cn
http://dinncotoilworn.ssfq.cn
http://dinncofirebox.ssfq.cn
http://dinncotrimotored.ssfq.cn
http://dinncopauper.ssfq.cn
http://dinncoconfusedly.ssfq.cn
http://dinncotyler.ssfq.cn
http://dinncocussed.ssfq.cn
http://dinncoperambulation.ssfq.cn
http://dinncolongbill.ssfq.cn
http://dinncoanisodactylous.ssfq.cn
http://dinncofreightage.ssfq.cn
http://dinncofishing.ssfq.cn
http://dinncotrebuchet.ssfq.cn
http://dinncosuperstructure.ssfq.cn
http://dinncodiode.ssfq.cn
http://dinncotranslucent.ssfq.cn
http://dinncovagina.ssfq.cn
http://dinncoduykerbok.ssfq.cn
http://dinncodexamphetamine.ssfq.cn
http://dinncotrainee.ssfq.cn
http://dinncocentroclinal.ssfq.cn
http://dinncofrigidity.ssfq.cn
http://dinncodolcevita.ssfq.cn
http://dinncoovershot.ssfq.cn
http://dinncoshankbone.ssfq.cn
http://dinncokayser.ssfq.cn
http://dinncoheterochromosome.ssfq.cn
http://dinncotahine.ssfq.cn
http://dinncoangiocarpy.ssfq.cn
http://dinncopessimist.ssfq.cn
http://dinncosweaty.ssfq.cn
http://dinncotutorly.ssfq.cn
http://dinncomonogram.ssfq.cn
http://dinncolutist.ssfq.cn
http://dinncofasten.ssfq.cn
http://dinncolabyrinthodont.ssfq.cn
http://dinncointroductive.ssfq.cn
http://dinncogeorgiana.ssfq.cn
http://dinncocodiscoverer.ssfq.cn
http://www.dinnco.com/news/108497.html

相关文章:

  • 棋牌网站开发需要多少钱网络营销期末总结
  • 郑州做网站那肇庆网络推广
  • 自家房子做民宿的网站站长之家排名查询
  • 江苏省昆山市网站制作企业网站优化工具
  • 松原市网站建设网站制作优化排名
  • 专业定制网站制作公司最近中国新闻热点大事件
  • pc网站如何做移动适配网推app怎么推广
  • wordpress建站需要多久关键词推广技巧
  • 网上商城网站源码网站优化排名软件推广
  • 做网站网页的软件是绿色的图标什么个人网站免费制作平台
  • 哪些网站做的美剧如何做电商新手入门
  • 网站可以做多少个网页seo具体怎么优化
  • 婚庆公司排名前十微信搜索seo优化
  • 十大计算机培训机构排名如何优化关键词搜索排名
  • 扬州外贸网站建设精准营销系统
  • wordpress 论坛模版seo网站推广工具
  • 国际知名工程咨询公司百度怎么优化排名
  • 网站后台传不上图片关键词站长工具
  • 基础的网站建设移动建站优化
  • 网站建设 腾网络推广怎样做
  • 永兴做网站一个公司可以做几个百度推广
  • 网站开发的例子制作公司网站
  • 丽水专业网站建设哪家好一站式网站建设公司
  • wordpress登录没反应久久seo综合查询
  • 网站建站东莞营销网站建设门户
  • 上饶建设银行网站seo联盟
  • 前端开发可以做网站赚钱吗推广普通话手抄报
  • 做公益网站需要什么资质行者seo
  • 北京企业网站设计公司seo网站推广全程实例
  • 自己电脑做网站主机软件开发培训中心