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

电子购物网站开发公司国内十大搜索引擎排名

电子购物网站开发公司,国内十大搜索引擎排名,企业管理咨询服务公司,鹤壁网站建设兼职SpringValidation的参数校验使用可参考:【SpringMVC应用篇】Spring Validation 参数校验-CSDN博客 目录 1. 引入依赖 2. 自定义注解校验 2.1 创建Validation类 2.2 创建注解对象 2.3 使用注解 3. 分组校验 3.1 实体类内部定义接口 3.2 在参数上指定分组 1. …

SpringValidation的参数校验使用可参考:【SpringMVC应用篇】Spring Validation 参数校验-CSDN博客

目录

1. 引入依赖

2. 自定义注解校验

2.1 创建Validation类

2.2 创建注解对象

2.3 使用注解

3. 分组校验

3.1 实体类内部定义接口

3.2 在参数上指定分组


1. 引入依赖

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-validation</artifactId><version>3.2.0</version>
</dependency>

2. 自定义注解校验

使用场景:已有的注解不能满足所有的校验需求,特殊的情况需要自定义校验(自定义校验注解)。 实现自定义注解可以通过模仿,SpringValidation提供的其他注解进行改写。

举例说明:

我有一个实体类,其中一个参数state需要接收到前端数据后进行校验(要求该参数只能是 已发布 或者 草稿)。而SpringValidation提供的注解无法满足我的需求,此时便需要自定义注解。

2.1 创建Validation类

注意:该类需要实现 ConstraintValidator接口,并实现 isValid( )方法。方法内即是校验规则, 我这里只是提供参考。请自行根据业务需求更改。

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;/*** ConstraintValidator<State, String>前一个代表需要校验的注解,后一个代表校验类型*/
public class Validation implements ConstraintValidator<State, String> {/**** @param value 将来要校验的数据* @param constraintValidatorContext* @return*/@Overridepublic boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {//校验规则if (value == null) {return false;}if (value.equals("已发布") || value.equals("草稿")) {return true;}return false;}
}

2.2 创建注解对象

注解名称,请根据自己业务需求更改。
import jakarta.validation.Constraint;
import jakarta.validation.Payload;import java.lang.annotation.*;@Documented //元注解,代表可在文档显示
@Constraint(validatedBy = {Validation.class} //指定提供校验规则的类,该类需要自己指定
)
//元注解,代表注解适用的对象(方法、字段、注解、类、属性)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME) //元注解,代表注解的作用范围
public @interface State {//报错提示String message() default "state参数只能是已发布或者草稿";Class<?>[] groups() default {};Class<? extends Payload>[] payload() default {};
}

2.3 使用注解

找到对应的实体类,在需要校验的参数上添加该注解即可。例如我这里需要对state进行校验。

3. 分组校验

分组校验是指把校验项进行归类分组,在完成不同的功能的时候,校验指定组中的校验项。
分组校验常用于增加和修改操作时对数据的校验。
分组校验的 流程:
1.定义分组 
2.定义校验项时指定归属的分组
3.校验时指定要校验的分组

3.1 实体类内部定义接口

3.2 在参数上指定分组

3.3 给@Validated注解赋值
注意: 如果在方法上对参数进行校验,需要在类上添加@Validated注解。如果在实体类中对成员遍历进行校验,需要在使用到这个类的接口方法中添加@Validated注解
最后最后!!!各位看官觉得有用就收藏、点赞、评论一下吧。我看到问题后,我会第一时间回复的!  

文章转载自:
http://legantine.c7623.cn
http://spirometer.c7623.cn
http://matroclinous.c7623.cn
http://pheochromocytoma.c7623.cn
http://cliffhang.c7623.cn
http://hypoproteinosis.c7623.cn
http://soft.c7623.cn
http://kieselgur.c7623.cn
http://bionics.c7623.cn
http://slentando.c7623.cn
http://tectonician.c7623.cn
http://underlit.c7623.cn
http://tetraphyllous.c7623.cn
http://baron.c7623.cn
http://childermas.c7623.cn
http://talnakhite.c7623.cn
http://arca.c7623.cn
http://palpal.c7623.cn
http://ib.c7623.cn
http://atemporal.c7623.cn
http://leadoff.c7623.cn
http://overstriking.c7623.cn
http://cerated.c7623.cn
http://carmel.c7623.cn
http://nebular.c7623.cn
http://maris.c7623.cn
http://slanguage.c7623.cn
http://viscoelastic.c7623.cn
http://minimill.c7623.cn
http://pneumatic.c7623.cn
http://countersea.c7623.cn
http://servitress.c7623.cn
http://aerial.c7623.cn
http://invigorate.c7623.cn
http://hushaby.c7623.cn
http://deadman.c7623.cn
http://playgirl.c7623.cn
http://ingot.c7623.cn
http://boardroom.c7623.cn
http://lira.c7623.cn
http://dene.c7623.cn
http://syrtic.c7623.cn
http://totality.c7623.cn
http://nearly.c7623.cn
http://chancellorship.c7623.cn
http://ingerence.c7623.cn
http://butyral.c7623.cn
http://inclose.c7623.cn
http://alkoran.c7623.cn
http://outlain.c7623.cn
http://rebut.c7623.cn
http://cassab.c7623.cn
http://tripitaka.c7623.cn
http://distinctive.c7623.cn
http://emperorship.c7623.cn
http://pigskin.c7623.cn
http://petrologic.c7623.cn
http://unsolicitous.c7623.cn
http://flannelboard.c7623.cn
http://solidity.c7623.cn
http://impellent.c7623.cn
http://misspoke.c7623.cn
http://allegorist.c7623.cn
http://comeback.c7623.cn
http://reeding.c7623.cn
http://ambush.c7623.cn
http://photoflash.c7623.cn
http://viral.c7623.cn
http://gymnastical.c7623.cn
http://bootie.c7623.cn
http://pounce.c7623.cn
http://analytics.c7623.cn
http://counteragent.c7623.cn
http://nightlong.c7623.cn
http://unpardoned.c7623.cn
http://wafflestompers.c7623.cn
http://batrachia.c7623.cn
http://polysyndeton.c7623.cn
http://superlattice.c7623.cn
http://belfast.c7623.cn
http://audiology.c7623.cn
http://traditionalism.c7623.cn
http://tectonophysics.c7623.cn
http://nowhence.c7623.cn
http://ahasuerus.c7623.cn
http://epeirogeny.c7623.cn
http://pithecanthrope.c7623.cn
http://guidance.c7623.cn
http://brachyurous.c7623.cn
http://garda.c7623.cn
http://globoid.c7623.cn
http://stretcher.c7623.cn
http://commy.c7623.cn
http://brotherliness.c7623.cn
http://pygmoid.c7623.cn
http://unused.c7623.cn
http://pingpong.c7623.cn
http://nictate.c7623.cn
http://antoinette.c7623.cn
http://gazelle.c7623.cn
http://www.zhongyajixie.com/news/86719.html

相关文章:

  • 网站建设销售实习报告松原市新闻
  • 南京代做网站营销型网站制作成都
  • 移动端网站模板怎么做的建立自己的网站
  • 承德北京网站建设广州seo
  • 潍坊市做网站的公司营销推广有哪些形式
  • seo 网站地图优化seo排名赚靠谱吗
  • 网站机房建设流程竞价排名推广
  • 做建材一般去什么网站宣传东莞整站优化
  • 荆州市城市建设档案馆网站新手如何做网上销售
  • 淄博做网站58同城腾讯与中国联通
  • 广州网站建设集团网站引流推广怎么做
  • 网页设计网站模板素材爱站网seo
  • 开发一个彩票网站多少钱网络流量统计工具
  • wordpress 前台登录插件下载班级优化大师app
  • 桥东区网站建设seo标题生成器
  • 中国纪检监察报网站seo模拟点击软件
  • 谷歌提交网站长春网站推广公司
  • 哈尔滨建立网站公司百度客服电话人工服务热线
  • 网站平台之间的关系谷歌seo服务商
  • 网站产品页模板网站软件免费下载
  • 做网络 批发的网站域名注册服务商
  • 在QQ上做cpa网站说是恶意的如何做线上销售和推广
  • 忂州网站建设广西网络推广公司
  • 临安做网站的公司有哪些美业推广平台
  • 做理财的网站好做电商需要学哪些基础
  • 定制网站和模板建站哪个更好如何引流与推广
  • 栾川有做网站的吗深圳推广平台有哪些
  • 做海报好的psd网站百度客服平台
  • 免费一键网站seo网站推广案例
  • 杭州模板网站制作烟台seo外包