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

岳阳网站建设设计青岛网站设计哪家

岳阳网站建设设计,青岛网站设计哪家,做一家网站费用,如何给网站加cdn目标 自定义一个用于校验邮政编码格式的注解ZipCode#xff0c;能够和现有的 Validation 兼容#xff0c;使用方式和其他校验注解保持一致#xff08;使用 Valid 注解接口参数#xff09;。 校验逻辑 有效格式 不能包含空格#xff1b;应为6位数字#xff1b; 不校验…目标 自定义一个用于校验邮政编码格式的注解ZipCode能够和现有的 Validation 兼容使用方式和其他校验注解保持一致使用 Valid 注解接口参数。 校验逻辑 有效格式 不能包含空格应为6位数字 不校验非空 邮政编码校验的是格式不校验是否为空null 或 空字符串。如果邮政编码为空直接通过校验 核心代码 需要定义的内容包含两个部分注解ZipCode和 校验器ZipCodeValidator。 注解ZipCode package com.example.core.validation.zipcode;import javax.validation.Constraint; import javax.validation.Payload; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target;import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.RetentionPolicy.RUNTIME;/*** 邮政编码。字符串必须是格式正确的邮政编码。正确格式为6位数字。* p* {code null} 或 空字符串是有效的能够通过校验。* p* 支持的类型字符串** author songguanxun* since 1.0*/ Target({FIELD}) Retention(RUNTIME) Documented Constraint(validatedBy ZipCodeValidator.class) public interface ZipCode {/*** return the error message template*/String message() default 邮政编码格式错误;/*** return the groups the constraint belongs to*/Class?[] groups() default {};/*** return the payload associated to the constraint*/Class? extends Payload[] payload() default {};} 校验器ZipCodeValidator package com.example.core.validation.zipcode;import com.example.core.constant.PatternConstant; import org.springframework.util.ObjectUtils;import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; import java.util.regex.Pattern;/*** 邮政编码格式校验器*/ public class ZipCodeValidator implements ConstraintValidatorZipCode, String {Overridepublic void initialize(ZipCode constraintAnnotation) {ConstraintValidator.super.initialize(constraintAnnotation);}Overridepublic boolean isValid(String value, ConstraintValidatorContext context) {if (ObjectUtils.isEmpty(value)) {return true;}if (value.contains( )) {resetMessage(context, 邮政编码格式错误不能包含空格);return false;}if (!isValid(value)) {resetMessage(context, 邮政编码格式错误);return false;}return true;}// 格式为6位数字private static final Pattern PATTERN Pattern.compile(PatternConstant.ZIP_CODE);/*** 是有效的格式*/private boolean isValid(CharSequence input) {return PATTERN.matcher(input).matches();}/*** 重置提示信息*/private void resetMessage(ConstraintValidatorContext context, String messageTemplate) {context.disableDefaultConstraintViolation();context.buildConstraintViolationWithTemplate(messageTemplate).addConstraintViolation();}} 用到的常量 package com.example.core.constant;/*** 模式-常量*/ public class PatternConstant {/*** 全部为数字*/public static final String NUMBERS ^\\d*$;/*** 邮政编码6位数字*/public static final String ZIP_CODE ^\\d{6}$; } 使用 ZipCode 放在需要校验格式的 邮政编码 字段上。 新增用户Param package com.example.web.response.model.param;import com.example.core.constant.PatternConstant; import com.example.core.validation.zipcode.ZipCode; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data;Schema(name 新增用户Param) public class UserAddParam {// 其他字段ZipCodeSchema(description 邮政编码, example 201100, pattern PatternConstant.ZIP_CODE)private String zipCode;} 校验效果 包含空格 不是6位数字 数字超过6位 包含非数字的字符
http://www.hkea.cn/news/14342531/

相关文章:

  • 网站建设需要什么软件企业中英文网站开发
  • 南通云网站建设现货交易平台排名
  • 网站空间租用费用pjax wordpress
  • 北京市住房与建设厅官方网站常用网站开发语言
  • 网站建设好了怎么在百度可以搜到网站方案怎么写
  • 自建网站备案网站建设的策划文案
  • 网站flash引导页做任务佣金的网站
  • 黑龙江建设网官方网站三类人员网站制作学什么软件
  • 西乡建网站公司网络推广培训一对一
  • 游仙建设局官方网站wordpress 左侧边栏
  • 教育课程网站建设网站空间换了 使用原有域名
  • 铁路网站建设网站源码下载平台源码
  • 网站开发课程设计建议个人网站首页设计优秀作品
  • 公司网站建设需要咨询什么问题广西壮族自治区招生考试院
  • 做网页网站 的公司怎么做自己的微信网站
  • 成都网站建设推建筑面积计算规范2023下载最新版
  • 朋友做的网站图片不显示不出来可以怎么找回密码
  • 设计微信公众号的网站吗手机搭建网站工具
  • 提高wordpress+权重廊坊视频优化方案
  • 湖南seo网站策划wordpress一栏一个主题
  • asp网站防注入代码wordpress创建搜索结果
  • 郴州市住房和城乡建设厅网站网页制作视频
  • 网站推广目标wordpress 爱在发烧
  • 流量型网站网站开发字体
  • 十堰做网站最专业的公司上海网站开发招聘
  • 选做旅游网站的课题分析企业年金值得交吗
  • 苏州网站建设 苏州网络推广专家河北住建城乡建设网站
  • 萍乡建站公司wordpress爱主题
  • php美食网站开发的意义wordpress页眉设置
  • 平凉市住房和城乡建设厅网站wordpress 角色权限