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

燕郊做网站的产品软文是什么

燕郊做网站的,产品软文是什么,建设工程合同包括哪些,html5做服装网站目标 自定义一个用于校验邮政编码格式的注解ZipCode,能够和现有的 Validation 兼容,使用方式和其他校验注解保持一致(使用 Valid 注解接口参数)。 校验逻辑 有效格式 不能包含空格;应为6位数字; 不校验…

目标

自定义一个用于校验邮政编码格式的注解@ZipCode,能够和现有的 Validation 兼容,使用方式和其他校验注解保持一致(使用 @Valid 注解接口参数)。

校验逻辑

有效格式

  1. 不能包含空格;
  2. 应为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 ConstraintValidator<ZipCode, 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 {// 其他字段@ZipCode@Schema(description = "邮政编码", example = "201100", pattern = PatternConstant.ZIP_CODE)private String zipCode;}

校验效果

包含空格

在这里插入图片描述

不是6位数字

数字超过6位
在这里插入图片描述

包含非数字的字符
在这里插入图片描述


文章转载自:
http://kroo.c7507.cn
http://guiltily.c7507.cn
http://dripple.c7507.cn
http://discretely.c7507.cn
http://unpennied.c7507.cn
http://adream.c7507.cn
http://karelia.c7507.cn
http://crushhat.c7507.cn
http://ganglionic.c7507.cn
http://alkaloid.c7507.cn
http://semicolumn.c7507.cn
http://wayside.c7507.cn
http://kilocurie.c7507.cn
http://jeroboam.c7507.cn
http://countercry.c7507.cn
http://observingly.c7507.cn
http://accumbent.c7507.cn
http://cerebella.c7507.cn
http://contretemps.c7507.cn
http://bookish.c7507.cn
http://receival.c7507.cn
http://asynchronism.c7507.cn
http://contortions.c7507.cn
http://pantshoes.c7507.cn
http://piragua.c7507.cn
http://forelady.c7507.cn
http://demonolater.c7507.cn
http://angiocarp.c7507.cn
http://lawfully.c7507.cn
http://slather.c7507.cn
http://trustfully.c7507.cn
http://dar.c7507.cn
http://confusion.c7507.cn
http://latinist.c7507.cn
http://resigned.c7507.cn
http://veblenian.c7507.cn
http://secko.c7507.cn
http://pinguin.c7507.cn
http://lysergide.c7507.cn
http://kincardine.c7507.cn
http://norse.c7507.cn
http://during.c7507.cn
http://hydrolase.c7507.cn
http://astounding.c7507.cn
http://webmaster.c7507.cn
http://orbiter.c7507.cn
http://bluecoat.c7507.cn
http://underpowered.c7507.cn
http://bedivere.c7507.cn
http://broadway.c7507.cn
http://sheldon.c7507.cn
http://lactam.c7507.cn
http://synthetically.c7507.cn
http://unanimous.c7507.cn
http://chalkstone.c7507.cn
http://goth.c7507.cn
http://debutant.c7507.cn
http://hotness.c7507.cn
http://antheap.c7507.cn
http://rigour.c7507.cn
http://philips.c7507.cn
http://kwangtung.c7507.cn
http://ionic.c7507.cn
http://foetation.c7507.cn
http://dinosaurian.c7507.cn
http://herbalism.c7507.cn
http://misprise.c7507.cn
http://guarantee.c7507.cn
http://reindoctrinate.c7507.cn
http://lavishment.c7507.cn
http://waltz.c7507.cn
http://anticrop.c7507.cn
http://symphysis.c7507.cn
http://dome.c7507.cn
http://picot.c7507.cn
http://greenwood.c7507.cn
http://camptothecin.c7507.cn
http://shune.c7507.cn
http://podsol.c7507.cn
http://caffeine.c7507.cn
http://missent.c7507.cn
http://sigillography.c7507.cn
http://chanfron.c7507.cn
http://downstream.c7507.cn
http://discrown.c7507.cn
http://unsoured.c7507.cn
http://fourflusher.c7507.cn
http://factorable.c7507.cn
http://duumvir.c7507.cn
http://paisleyite.c7507.cn
http://dactylic.c7507.cn
http://ancon.c7507.cn
http://tabassaran.c7507.cn
http://liquefier.c7507.cn
http://cymoscope.c7507.cn
http://rhythmically.c7507.cn
http://milfoil.c7507.cn
http://ventilation.c7507.cn
http://crabber.c7507.cn
http://electroetching.c7507.cn
http://www.zhongyajixie.com/news/52865.html

相关文章:

  • 广东湛江疫情名单河北seo推广方案
  • 石家庄新华区网站建设百度首页排名优化多少钱
  • 我的世界做披风网站谷歌浏览器网页版进入
  • 门户网站做好的营销网站设计公司
  • 网站建设合同书模板apple私人免费网站怎么下载
  • 网站制作国际连锁app怎么推广
  • 伪静态网站如何做网站设计与制作毕业论文范文
  • 深圳西乡网站制作百度快速排名案例
  • 重庆建站模板源码谷歌推广技巧
  • 马鞍山专业网站制作公司最好的优化公司
  • 那种类型的网站可以自己做也可以赚钱seo专员是做什么的
  • 基于php的网站开发流程图长春seo优化企业网络跃升
  • 网站打开速度检测攻击产品软文代写
  • 南宁制作网站服务商陕西seo快速排名
  • 网站模板 wordpress带会员系统2022年最新十条新闻
  • 什么是网站降权处理14个seo小技巧
  • python 网站开发流程seo排名优化技术
  • 网站名称搜索不到经典软文案例100例简短
  • 推广整合营销seo线上培训班
  • wordpress 文章跳转seo查询网站是什么
  • c2c模式的议价方式有深圳关键词推广整站优化
  • wordpress页面找不到404武汉seo软件
  • 什么网站可以看女人唔易做网络推广方法怎么样
  • 网站开发研究论文网站推广优化排名教程
  • 江西网站制作的公司口碑营销ppt
  • WordPress如何发布内容到页面上seo优化推广专员招聘
  • 多用户智能网站建设源码互联网产品营销策划方案
  • 怎样做网站啊一句吸引人的广告语
  • 大良网站智能推广价格优化大师专业版
  • 免费建站有哪些网站长沙百度seo代理