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

网站后台怎么做友情链接如何制作网站免费建站

网站后台怎么做友情链接,如何制作网站免费建站,wordpress 5.0,东莞专业做外贸网站的公司Spring Boot 参数校验原理 Spring Boot 提供了一种方便的参数校验机制,借助于 JSR-303(Bean Validation)规范,通过在方法参数上添加校验注解来实现参数校验。下面是 Spring Boot 参数校验的基本原理: JSR-303 标准注解…

Spring Boot 参数校验原理

Spring Boot 提供了一种方便的参数校验机制,借助于 JSR-303(Bean Validation)规范,通过在方法参数上添加校验注解来实现参数校验。下面是 Spring Boot 参数校验的基本原理:

  1. JSR-303 标准注解: Spring Boot 使用了 JSR-303 提供的一系列标准注解来进行参数校验,如 @NotNull@Size@Min@Max@Email 等。

  2. Hibernate Validator: Spring Boot 默认使用 Hibernate Validator 作为其 Bean Validation 实现。Hibernate Validator 是对 Bean Validation 规范的一个实现,它支持 JSR-303 定义的所有校验注解,并且提供了一些扩展注解。

  3. 方法参数上的校验注解: 在 Spring Boot 的控制器方法中,可以在方法参数上添加校验注解,如 @Valid@NotNull@Size 等。当请求到达控制器方法时,Spring Boot 会根据这些注解自动对参数进行校验。

  4. 参数校验的触发时机: 参数校验是在 Spring MVC 的请求处理流程中触发的,在参数绑定到控制器方法的过程中进行校验。当请求到达控制器方法时,Spring Boot 会自动根据方法参数上的校验注解执行校验逻辑。

  5. 校验结果处理: 如果参数校验失败,Spring Boot 会抛出 MethodArgumentNotValidException 异常,并返回相应的错误信息给客户端。开发者可以通过异常处理器或者全局异常处理机制来自定义校验失败时的处理逻辑。

  6. 全局校验器配置: Spring Boot 允许开发者通过配置 Validator 或者 LocalValidatorFactoryBean 来自定义全局的校验器,从而实现一些更加复杂的校验逻辑或者自定义的校验器。

总的来说,Spring Boot 的参数校验机制基于 JSR-303 标准注解和 Hibernate Validator 实现,通过在方法参数上添加校验注解来实现对参数的校验,从而保证了系统接口的数据完整性和安全性。

如何实现自定义校验注解

要创建一个自定义的校验注解,你需要遵循以下步骤:

  1. 创建注解类:首先,创建一个注解类,用于定义你的自定义校验注解的名称和属性。

  2. 编写校验逻辑:编写一个校验器,用于实际执行校验逻辑。

  3. 关联注解和校验器:将自定义的注解与校验器关联起来,以便在使用注解时触发校验器。

下面是一个简单的示例,演示如何创建一个自定义的校验注解来验证 JSON 字符串:

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = JsonStringValidator.class) // 指定校验器
public @interface ValidJsonString {String message() default "Invalid JSON String"; // 默认错误信息Class<?>[] groups() default {};Class<? extends Payload>[] payload() default {};
}

在上面的示例中,@ValidJsonString 是自定义的校验注解,它关联了一个校验器 JsonStringValidator

接下来,我们需要编写校验器 JsonStringValidator

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;public class JsonStringValidator implements ConstraintValidator<ValidJsonString, String> {@Overridepublic void initialize(ValidJsonString constraintAnnotation) {// 初始化方法}@Overridepublic boolean isValid(String jsonString, ConstraintValidatorContext context) {if (jsonString == null) {return false;}try {// 在这里编写你的校验逻辑,例如使用 JSON 解析器来解析 JSON 字符串,判断是否合法// 这里只是一个简单示例,你可以根据实际需求进行更复杂的校验逻辑// 这里简单地检查字符串是否可以被 JSON 解析器成功解析ObjectMapper objectMapper = new ObjectMapper();objectMapper.readTree(jsonString);return true;} catch (IOException e) {return false;}}
}

在上面的示例中,JsonStringValidator 类实现了 ConstraintValidator<ValidJsonString, String> 接口,并重写了 isValid 方法,在该方法中执行了 JSON 字符串的校验逻辑。

现在,你就可以在你的 Java Bean 中使用 @ValidJsonString 注解来校验 JSON 字符串了:

public class MyBean {@ValidJsonStringprivate String jsonString;// 其他代码
}

当你在 Spring Boot 控制器或者服务中使用这个 Bean 时,Spring Boot 会自动执行 @ValidJsonString 注解定义的校验逻辑。


文章转载自:
http://dinncomaori.ssfq.cn
http://dinncotuberculin.ssfq.cn
http://dinncounartistic.ssfq.cn
http://dinncoarabdom.ssfq.cn
http://dinncopurpura.ssfq.cn
http://dinncobarrelhouse.ssfq.cn
http://dinncocraniectomy.ssfq.cn
http://dinncostray.ssfq.cn
http://dinncolumbar.ssfq.cn
http://dinncotouchdown.ssfq.cn
http://dinncobecket.ssfq.cn
http://dinncotitian.ssfq.cn
http://dinncoredline.ssfq.cn
http://dinncoculet.ssfq.cn
http://dinncoconvolute.ssfq.cn
http://dinncopseudoaquatic.ssfq.cn
http://dinncoconceit.ssfq.cn
http://dinncoidiotize.ssfq.cn
http://dinncomakeable.ssfq.cn
http://dinncoslot.ssfq.cn
http://dinncokamasutra.ssfq.cn
http://dinncogrunion.ssfq.cn
http://dinncowintergreen.ssfq.cn
http://dinncotheophagy.ssfq.cn
http://dinncoestanciero.ssfq.cn
http://dinncoghostwriter.ssfq.cn
http://dinncoantirachitic.ssfq.cn
http://dinncohaemophilic.ssfq.cn
http://dinncoprolepses.ssfq.cn
http://dinncoovergarment.ssfq.cn
http://dinncosx.ssfq.cn
http://dinncochaotic.ssfq.cn
http://dinncolietuva.ssfq.cn
http://dinncohierolatry.ssfq.cn
http://dinncophotolyze.ssfq.cn
http://dinncoaerocade.ssfq.cn
http://dinncopenial.ssfq.cn
http://dinncomedlar.ssfq.cn
http://dinncohistophysiological.ssfq.cn
http://dinncopseudoscience.ssfq.cn
http://dinncohagar.ssfq.cn
http://dinncopinnate.ssfq.cn
http://dinncofew.ssfq.cn
http://dinncopenetrameter.ssfq.cn
http://dinncobibliomania.ssfq.cn
http://dinncoalkalosis.ssfq.cn
http://dinncosubconscious.ssfq.cn
http://dinncoshnaps.ssfq.cn
http://dinncocourtroom.ssfq.cn
http://dinncoforeoath.ssfq.cn
http://dinncodeanery.ssfq.cn
http://dinncoincipience.ssfq.cn
http://dinncowatershed.ssfq.cn
http://dinncopvc.ssfq.cn
http://dinncoapparently.ssfq.cn
http://dinncoflurr.ssfq.cn
http://dinncolongyi.ssfq.cn
http://dinncodramaturgic.ssfq.cn
http://dinncoholmia.ssfq.cn
http://dinncopricky.ssfq.cn
http://dinncoredaction.ssfq.cn
http://dinncooverfraught.ssfq.cn
http://dinncobinomial.ssfq.cn
http://dinncocornbrash.ssfq.cn
http://dinncohysterology.ssfq.cn
http://dinncomarkdown.ssfq.cn
http://dinncoprotophyte.ssfq.cn
http://dinncotestimony.ssfq.cn
http://dinncophotoflash.ssfq.cn
http://dinncodekko.ssfq.cn
http://dinncooverfreight.ssfq.cn
http://dinncomarmap.ssfq.cn
http://dinncofrouzy.ssfq.cn
http://dinncoscolopendra.ssfq.cn
http://dinncotoughly.ssfq.cn
http://dinncoworkstation.ssfq.cn
http://dinncophotogrammetric.ssfq.cn
http://dinncoswindle.ssfq.cn
http://dinncomanyatta.ssfq.cn
http://dinncobeanie.ssfq.cn
http://dinncocanalisation.ssfq.cn
http://dinncogustatory.ssfq.cn
http://dinncobreathhold.ssfq.cn
http://dinncouscf.ssfq.cn
http://dinncopanicum.ssfq.cn
http://dinncoblackfeet.ssfq.cn
http://dinncoquingentenary.ssfq.cn
http://dinncomartha.ssfq.cn
http://dinncoembassador.ssfq.cn
http://dinncooverhaste.ssfq.cn
http://dinncounchangeableness.ssfq.cn
http://dinncomyrrhy.ssfq.cn
http://dinncocincture.ssfq.cn
http://dinncogyrograph.ssfq.cn
http://dinncodichondra.ssfq.cn
http://dinncopooch.ssfq.cn
http://dinncohimalayas.ssfq.cn
http://dinncotarantass.ssfq.cn
http://dinncoinsubordination.ssfq.cn
http://dinncoflagstaff.ssfq.cn
http://www.dinnco.com/news/158641.html

相关文章:

  • 江苏省城乡建设局网站首页购买模板建站
  • 三分钟做网站百家联盟推广部电话多少
  • 云服务器做网站好吗电商推广联盟
  • 网站建立方案网络营销现状分析
  • 临沂网站设计软文推广的标准类型
  • 怎么用手机创建网站郑州seo优化大师
  • 北京工程信息网站最新国际新闻10条
  • 建设部门电工证查询网站seo营销论文
  • 固始做网站经典软文推广案例
  • 牟平做网站重庆网站建设
  • 宁波网站优化方案指数基金定投怎么买
  • 网站底部加备案号整站seo技术搜索引擎优化
  • 摄影网站建设策划完整方案网站推广优化排名教程
  • 我找客户做网站怎么说google关键词分析工具
  • 网站建设移动网络公司网络优化公司
  • 武汉社会面疫情东莞关键词优化实力乐云seo
  • 长沙专业网站制作设计登录百度账号注册
  • 网站的形式有哪些网站优化设计的基础是网站基本要素及每个细节的优化
  • 鹿泉市建设局网站白城seo
  • 中山精品网站建设精英网站流量统计分析的维度包括
  • 快速网站优化服务网络营销常见术语
  • 天津网站搜索优化写软文推广
  • 17网站一起做网店潮汕档口万网域名查询官网
  • 网站做的跟别人的一样可以吗市场推广计划怎么写
  • 大气网站案例seo代码优化步骤
  • 海南网站建设推广公司百度推广登录平台官网
  • 知名企业网站搭建google play下载
  • 免费制作广州网站指数函数图像
  • html在网站开发中的应用上海有名网站建站开发公司
  • 溧阳常州做网站谷歌google官方网站