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

Spring-boot读书笔记一弄懂ConstraintValidatorPassword, String

In ConstraintValidator<Password, String>, the two generic type parameters are:

First parameter: Password

  • This is the annotation type that this validator handles
  • It's a custom validation annotation (like @Password) that you would create
  • When someone uses @Password on a field, this validator will be called
  • Example: @Password private String userPassword;

Second parameter: String

  • This is the data type of the value being validated
  • It tells the validator what type of object it will receive in the isValid() method
  • In this case, it expects a String value (the password)
  • The isValid(String password, ...) method parameter matches this type

How it works:

  • You create a @Password annotation
  • Apply it to a String field: @Password String myPassword
  • When validation runs, this validator receives the String value
  • The isValid() method validates that String and returns true/false

Other examples:

  • ConstraintValidator<Email, String> - validates email strings
  • ConstraintValidator<Min, Integer> - validates minimum integer values
  • ConstraintValidator<NotNull, Object> - validates any object is not null

The generic types ensure type safety between the annotation and the value being validated.

http://www.gsyq.cn/news/189150.html

相关文章:

  • Java毕设项目:基于SpringBoot的广西旅游景点数据分析系统与设计(源码+文档,讲解、调试运行,定制等)
  • Java指针p
  • 【接口测试】2_项目实战 _接口自动化测试框架
  • 基于图注意力的时空数据因果链推理分析
  • 光量子计算机再达“量子优势”,意义何在?
  • 飞行影院设备价格解析及性价比分析
  • Electron for 鸿蒙PC项目实战案例之水果消消乐 - 详解
  • 牙齿拥挤数据集3206张VOC+YOLO格式
  • 期货反向跟单—从小白到高手进阶历程 六十二(期货交易中的逆向智慧)
  • 【课程设计/毕业设计】基于springboot的明星周边商城系统设计与实现基于SpringBoot的爱豆明星周边销售管理系统的设计与实现【附源码、数据库、万字文档】
  • 盘点2025磁性材料/器件上市企业扩产投资动向
  • 12月读书笔记-3
  • 磁性元件与电源行业评选评审团公布
  • 需求梳理痛点如何破解?理论支撑与CoCode实践探索
  • CSDN年度技术趋势预测文章大纲
  • Kafka Connect x AutoMQ: Zero Cross-AZ Data Pipeline
  • 半导体行业2025年最便宜10款MCU芯片
  • 私有部署问卷系统操作实战记录-DWSurvey
  • Day 51 在预训练 ResNet18 中注入
  • 洞察趋势:低代码如何驱动企业数字化转型效率提升?
  • 西电考研 | 26官方复试专业课参考书目汇总,强烈推荐!
  • DeepSeek总结的SQL 数独:约束编程
  • Java计算机毕设之基于Springboot的牧场管理系统的设计与实现养殖管理记录牲畜档案(完整前后端代码+说明文档+LW,调试定制等)
  • Overcoming the uncertainty challenges in detecting building changes from remote sensing images
  • 全网最详细的软件测试面试题总结+基础知识(完整版)
  • 链表的逻辑 - f
  • AI论文降重平台排名:9款工具实测,开题报告撰写功能同样出色
  • 【深入理解 Android 中的 build.gradle 文件】
  • Linux命令-ifconfig命令(配置和显示网络接口的信息)
  • 原理图Capture CIS 设计的学习2