zoukankan      html  css  js  c++  java
  • @NotEmpty、@NotNull、@NotBlank注解解析

    源码解析

    • @NotEmpty根据JDK源码注释说明,该注解只能应用于char可读序列(可简单理解为String对象),colleaction,map,array上,因为该注解要求的是对象不为null且size>0,所以只有上述对象是拥有size属性的,而Integer,Long等基础对象包装类没有该属性
    /**
     * The annotated element must not be {@code null} nor empty. Supported types are:
     * <ul>
     * <li>{@code CharSequence} (length of character sequence is evaluated)</li>  char值得可读序列,CharSequence的实现类有String, StringBuffer, StringBuilder, CharBuffer
     * <li>{@code Collection} (collection size is evaluated)</li> 集合类
     * <li>{@code Map} (map size is evaluated)</li> map散列表
     * <li>Array (array length is evaluated)</li> 数组
     * </ul>
     */
    
    • @NotNull,表示不能为null,但可以为empty,与@NotEmpty注解相比是少了size属性,所以"Accepts any type"可以接受任何类型对象
    /**
     * The annotated element must not be {@code null}.
     * Accepts any type.
     */
    
    • @NotBlank,"Accepts {@code CharSequence}"表明只应用于char值可读序列,则可以简单理解为只用于String,且不能为null,"non-whitespace"表示不能是空白字符,所以校验字符串是调用trim()方法之后的字符串长度大于0
    /**
     * The annotated element must not be {@code null} and must contain at least one
     * non-whitespace character. Accepts {@code CharSequence}.
     */
    
  • 相关阅读:
    DJango简单的后台定义登录验证
    简单聊聊HTTP/TCP/IP协议
    简单的线程说明
    设计模式 -- 常用设计模式
    网络知识 -- 第二部
    c#利用脚本,本地执行linux命令
    Json和类之间的转化
    关于地址映射穿透和套接字复用的说明
    多线程调用中的注意事项
    Task多线程的常规用法
  • 原文地址:https://www.cnblogs.com/xiguadadage/p/11989978.html
Copyright © 2011-2022 走看看