类 StringUtils

java.lang.Object
com.baomidou.mybatisplus.core.toolkit.StringUtils

public final class StringUtils extends Object
String 工具类
从以下版本开始:
2016-08-18
作者:
D.Yang, hcl, hcl
  • 字段详细资料

    • IS

      public static final String IS
      字符串 is
      另请参阅:
    • UNDERLINE

      public static final char UNDERLINE
      下划线字符
      另请参阅:
    • MP_SQL_PLACE_HOLDER

      public static final Pattern MP_SQL_PLACE_HOLDER
      MP 内定义的 SQL 占位符表达式,匹配诸如 {0},{1},{2} ... 的形式
  • 构造器详细资料

    • StringUtils

      public StringUtils()
  • 方法详细资料

    • isBlank

      public static boolean isBlank(CharSequence cs)
      判断字符串中是否全是空白字符
      参数:
      cs - 需要判断的字符串
      返回:
      如果字符串序列是 null 或者全是空白,返回 true
    • toStringTrim

      public static String toStringTrim(Object o)
      对象转为字符串去除左右空格
      参数:
      o - 带转换对象
      返回:
    • isNotBlank

      public static boolean isNotBlank(CharSequence cs)
      另请参阅:
    • isEmpty

      public static boolean isEmpty(CharSequence cs)
    • isNotEmpty

      public static boolean isNotEmpty(CharSequence cs)
    • isCamel

      public static boolean isCamel(String str)
      判断字符串是不是驼峰命名
    • 包含 '_' 不算
    • 首字母大写的不算
    • 参数:
      str - 字符串
      返回:
      结果
    • isNotColumnName

      public static boolean isNotColumnName(String str)
      判断字符串是否符合数据库字段的命名
      参数:
      str - 字符串
      返回:
      判断结果
    • getTargetColumn

      public static String getTargetColumn(String column)
      获取真正的字段名
      参数:
      column - 字段名
      返回:
      字段名
    • camelToUnderline

      public static String camelToUnderline(String param)
      字符串驼峰转下划线格式
      参数:
      param - 需要转换的字符串
      返回:
      转换好的字符串
    • underlineToCamel

      public static String underlineToCamel(String param)
      字符串下划线转驼峰格式
      参数:
      param - 需要转换的字符串
      返回:
      转换好的字符串
    • firstToLowerCase

      public static String firstToLowerCase(String param)
      首字母转换小写
      参数:
      param - 需要转换的字符串
      返回:
      转换好的字符串
    • matches

      public static boolean matches(String regex, String input)
      正则表达式匹配
      参数:
      regex - 正则表达式字符串
      input - 要匹配的字符串
      返回:
      如果 input 符合 regex 正则表达式格式, 返回true, 否则返回 false;
    • sqlArgsFill

      public static String sqlArgsFill(String content, Object... args)
      替换 SQL 语句中的占位符,例如输入 SELECT * FROM test WHERE id = {0} AND name = {1} 会被替换为 SELECT * FROM test WHERE id = 1 AND name = 'MP'

      当数组中参数不足时,该方法会抛出错误:数组下标越界ArrayIndexOutOfBoundsException

      参数:
      content - 填充内容
      args - 填充参数
    • replace

      public static StringBuilder replace(CharSequence src, Pattern ptn, BiIntFunction<Matcher,CharSequence> replacer)
      根据指定的表达式替换字符串中指定格式的部分

      BiIntFunction 中的 第二个 参数将传递 参数在字符串中的索引

      参数:
      src - 源字符串
      ptn - 需要替换部分的正则表达式
      replacer - 替换处理器
      返回:
      返回字符串构建起
    • sqlParam

      public static String sqlParam(Object obj)
      获取SQL PARAMS字符串
    • quotaMark

      public static String quotaMark(Object obj)
      使用单引号包含字符串
      参数:
      obj - 原字符串
      返回:
      单引号包含的原字符串
    • quotaMarkList

      public static String quotaMarkList(Collection<?> coll)
      使用单引号包含字符串
      参数:
      coll - 集合
      返回:
      单引号包含的原字符串的集合形式
    • concatCapitalize

      public static String concatCapitalize(String concatStr, String str)
      拼接字符串第二个字符串第一个字母大写
    • checkValNotNull

      public static boolean checkValNotNull(Object object)
      判断对象是否不为空
      参数:
      object - ignore
      返回:
      ignore
    • checkValNull

      public static boolean checkValNull(Object object)
      判断对象是否为空
      参数:
      object - ignore
      返回:
      ignore
    • containsUpperCase

      public static boolean containsUpperCase(String word)
      包含大写字母
      参数:
      word - 待判断字符串
      返回:
      ignore
    • isCapitalMode

      public static boolean isCapitalMode(String word)
      是否为大写命名
      参数:
      word - 待判断字符串
      返回:
      ignore
    • isMixedMode

      public static boolean isMixedMode(String word)
      是否为驼峰下划线混合命名
      参数:
      word - 待判断字符串
      返回:
      ignore
    • endsWith

      public static boolean endsWith(String str, String suffix)
      判断是否以某个字符串结尾(区分大小写) Check if a String ends with a specified suffix.

      nulls are handled without exceptions. Two null references are considered to be equal. The comparison is case sensitive.

       StringUtils.endsWith(null, null)      = true
       StringUtils.endsWith(null, "abcdef")  = false
       StringUtils.endsWith("def", null)     = false
       StringUtils.endsWith("def", "abcdef") = true
       StringUtils.endsWith("def", "ABCDEF") = false
       

      参数:
      str - the String to check, may be null
      suffix - the suffix to find, may be null
      返回:
      true if the String ends with the suffix, case sensitive, or both null
      从以下版本开始:
      2.4
      另请参阅:
    • isCharSequence

      public static boolean isCharSequence(Class<?> clazz)
      是否为CharSequence类型
      参数:
      clazz - class
      返回:
      true 为是 CharSequence 类型
    • prefixToLower

      public static String prefixToLower(String rawString, int index)
      前n个首字母小写,之后字符大小写的不变
      参数:
      rawString - 需要处理的字符串
      index - 多少个字符(从左至右)
      返回:
      ignore
    • removePrefixAfterPrefixToLower

      public static String removePrefixAfterPrefixToLower(String rawString, int index)
      删除字符前缀之后,首字母小写,之后字符大小写的不变

      StringUtils.removePrefixAfterPrefixToLower( "isUser", 2 ) = user

      StringUtils.removePrefixAfterPrefixToLower( "isUserInfo", 2 ) = userInfo

      参数:
      rawString - 需要处理的字符串
      index - 删除多少个字符(从左至右)
      返回:
      ignore
    • camelToHyphen

      public static String camelToHyphen(String input)
      驼峰转连字符

      StringUtils.camelToHyphen( "managerAdminUserService" ) = manager-admin-user-service

      参数:
      input - ignore
      返回:
      以'-'分隔
      另请参阅:
    • equals

      public static boolean equals(CharSequence cs1, CharSequence cs2)

      比较两个字符串,相同则返回true。字符串可为null

      对字符串大小写敏感

       StringUtils.equals(null, null)   = true
       StringUtils.equals(null, "abc")  = false
       StringUtils.equals("abc", null)  = false
       StringUtils.equals("abc", "abc") = true
       StringUtils.equals("abc", "ABC") = false
       
      参数:
      cs1 - 第一个字符串, 可为 null
      cs2 - 第二个字符串, 可为 null
      返回:
      true 如果两个字符串相同, 或者都为 null
      另请参阅:
    • sqlInjectionReplaceBlank

      public static String sqlInjectionReplaceBlank(String str)
      SQL 注入字符串去除空白内容:
      • \n 回车
      • \t 水平制表符
      • \s 空格
      • \r 换行
      参数:
      str - 字符串
    • replaceAllBlank

      public static String replaceAllBlank(String str)
      字符串去除空白内容:
      • \n 回车
      • \t 水平制表符
      • \s 空格
      • \r 换行
      参数:
      str - 字符串