public final class StringUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
EMPTY
空字符
|
static String |
IS
字符串 is
|
static Pattern |
MP_SQL_PLACE_HOLDER
MP 内定义的 SQL 占位符表达式,匹配诸如 {0},{1},{2} ...
|
static char |
UNDERLINE
下划线字符
|
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
blob2String(Blob blob)
Blob 转为 String 格式
|
static String |
camelToHyphen(String input)
驼峰转连字符
StringUtils.camelToHyphen( "managerAdminUserService" ) =
manager-admin-user-service
|
static String |
camelToUnderline(String param)
字符串驼峰转下划线格式
|
static String |
capitalize(String str)
字符串第一个字母大写
|
static boolean |
checkValNotNull(Object object)
判断对象是否为空
|
static boolean |
checkValNull(Object object)
判断对象是否为空
|
static String |
concatCapitalize(String concatStr,
String str)
拼接字符串第二个字符串第一个字母大写
|
static boolean |
containsLowerCase(String s) |
static boolean |
containsUpperCase(String word)
包含大写字母
|
static boolean |
endsWith(String str,
String suffix)
Check if a String ends with a specified suffix.
|
static boolean |
endsWithIgnoreCase(String str,
String suffix)
Case insensitive check if a String ends with a specified suffix.
|
static String |
firstCharToLower(String rawString)
第一个首字母小写,之后字符大小写的不变
StringUtils.firstCharToLower( "UserService" ) = userService
StringUtils.firstCharToLower( "UserServiceImpl" ) = userServiceImpl
|
static String |
firstToLowerCase(String param)
首字母转换小写
|
static String |
format(String target,
Object... params)
安全的进行字符串 format
|
static String |
getTargetColumn(String column)
获取真正的字段名
|
static String |
guessGetterName(String name,
Class<?> type)
猜测方法属性对应的 Getter 名称,具体规则请参考 JavaBeans 规范
|
static boolean |
isBlank(CharSequence cs) |
static boolean |
isBoolean(Class<?> propertyCls)
已过时。
|
static boolean |
isCamel(String str)
判断字符串是不是驼峰命名
包含 '_' 不算
首字母大写的不算
|
static boolean |
isCapitalMode(String word)
是否为大写命名
|
static boolean |
isCharSequence(Class<?> clazz)
是否为CharSequence类型
|
static boolean |
isEmpty(CharSequence cs)
已过时。
|
static boolean |
isMixedMode(String word)
是否为驼峰下划线混合命名
|
static boolean |
isNotBlank(CharSequence cs) |
static boolean |
isNotColumnName(String str)
判断字符串是否符合数据库字段的命名
|
static boolean |
isNotEmpty(CharSequence cs)
已过时。
|
static boolean |
isUpperCase(String str)
判断字符串是否为纯大写字母
|
static boolean |
matches(String regex,
String input)
正则表达式匹配
|
static String |
prefixToLower(String rawString,
int index)
前n个首字母小写,之后字符大小写的不变
|
static String |
quotaMark(Object obj)
使用单引号包含字符串
|
static String |
quotaMarkList(Collection<?> coll)
使用单引号包含字符串
|
static String |
removeIsPrefixIfBoolean(String propertyName,
Class<?> propertyType)
去除boolean类型is开头的字符串
|
static String |
removePrefixAfterPrefixToLower(String rawString,
int index)
删除字符前缀之后,首字母小写,之后字符大小写的不变
StringUtils.removePrefixAfterPrefixToLower( "isUser", 2 ) = user
StringUtils.removePrefixAfterPrefixToLower( "isUserInfo", 2 ) = userInfo
|
static String |
removeWordWithComma(String s,
String p)
已过时。
3.1.1
|
static StringBuilder |
replace(CharSequence src,
Pattern ptn,
BiIntFunction<Matcher,CharSequence> replacer)
根据指定的表达式替换字符串中指定格式的部分
BiIntFunction 中的 第二个 参数将传递 参数在字符串中的索引
|
static String |
resolveFieldName(String getMethodName)
解析 getMethodName -> propertyName
|
static String[] |
split(String str,
String separatorChars)
Splits the provided text into an array, separators specified.
|
static List<String> |
splitWorker(String str,
String separatorChars,
int max,
boolean preserveAllTokens)
Performs the logic for the
split and splitPreserveAllTokens
methods that return a maximum array length. |
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
|
static String |
sqlParam(Object obj)
获取SQL PARAMS字符串
|
static String |
underlineToCamel(String param)
字符串下划线转驼峰格式
|
static String |
upperFirst(String src)
大写第一个字母
|
public static final char UNDERLINE
public static final Pattern MP_SQL_PLACE_HOLDER
public static String format(String target, Object... params)
target - 目标字符串params - format 参数public static String blob2String(Blob blob)
blob - Blob 对象@Deprecated public static boolean isEmpty(CharSequence cs)
cs - 需要判断字符串public static boolean isBlank(CharSequence cs)
@Deprecated public static boolean isNotEmpty(CharSequence cs)
cs - 需要判断字符串public static boolean isNotBlank(CharSequence cs)
public static String guessGetterName(String name, Class<?> type)
name - 属性名称type - 属性类型public static boolean isCamel(String str)
str - 字符串public static boolean isNotColumnName(String str)
str - 字符串public static String getTargetColumn(String column)
column - 字段名public static String camelToUnderline(String param)
param - 需要转换的字符串public static String resolveFieldName(String getMethodName)
getMethodName - 需要解析的public static String underlineToCamel(String param)
param - 需要转换的字符串public static String firstToLowerCase(String param)
param - 需要转换的字符串public static boolean isUpperCase(String str)
str - 要匹配的字符串public static boolean matches(String regex, String input)
regex - 正则表达式字符串input - 要匹配的字符串public static String sqlArgsFill(String content, Object... args)
当数组中参数不足时,该方法会抛出错误:数组下标越界ArrayIndexOutOfBoundsException
content - 填充内容args - 填充参数public static StringBuilder replace(CharSequence src, Pattern ptn, BiIntFunction<Matcher,CharSequence> replacer)
BiIntFunction 中的 第二个 参数将传递 参数在字符串中的索引
src - 源字符串ptn - 需要替换部分的正则表达式replacer - 替换处理器public static String quotaMarkList(Collection<?> coll)
coll - 集合public static String concatCapitalize(String concatStr, String str)
public static boolean checkValNotNull(Object object)
object - ignorepublic static boolean checkValNull(Object object)
object - ignorepublic static boolean containsUpperCase(String word)
word - 待判断字符串public static boolean isCapitalMode(String word)
word - 待判断字符串public static boolean isMixedMode(String word)
word - 待判断字符串public static boolean endsWith(String str, String 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 nullsuffix - the suffix to find, may be nulltrue if the String ends with the suffix, case sensitive,
or both nullString.endsWith(String)public static boolean endsWithIgnoreCase(String str, String suffix)
nulls are handled without exceptions. Two null
references are considered to be equal. The comparison is case insensitive.
StringUtils.endsWithIgnoreCase(null, null) = true
StringUtils.endsWithIgnoreCase(null, "abcdef") = false
StringUtils.endsWithIgnoreCase("def", null) = false
StringUtils.endsWithIgnoreCase("def", "abcdef") = true
StringUtils.endsWithIgnoreCase("def", "ABCDEF") = false
str - the String to check, may be nullsuffix - the suffix to find, may be nulltrue if the String ends with the suffix, case
insensitive, or both nullString.endsWith(String)public static String[] split(String str, String separatorChars)
The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.
A null input String returns null. A null
separatorChars splits on whitespace.
StringUtils.split(null, *) = null
StringUtils.split("", *) = []
StringUtils.split("abc def", null) = ["abc", "def"]
StringUtils.split("abc def", " ") = ["abc", "def"]
StringUtils.split("abc def", " ") = ["abc", "def"]
StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
str - the String to parse, may be nullseparatorChars - the characters used as the delimiters, null
splits on whitespacenull if null String inputpublic static List<String> splitWorker(String str, String separatorChars, int max, boolean preserveAllTokens)
split and splitPreserveAllTokens
methods that return a maximum array length.str - the String to parse, may be nullseparatorChars - the separate charactermax - the maximum number of elements to include in the
array. A zero or negative value implies no limit.preserveAllTokens - if true, adjacent separators are treated as
empty token separators; if false, adjacent
separators are treated as one separator.null if null String inputpublic static boolean isCharSequence(Class<?> clazz)
clazz - classpublic static String removeIsPrefixIfBoolean(String propertyName, Class<?> propertyType)
propertyName - 字段名propertyType - 字段类型@Deprecated public static boolean isBoolean(Class<?> propertyCls)
ClassUtils.isBoolean(Class)propertyCls - ignorepublic static String firstCharToLower(String rawString)
StringUtils.firstCharToLower( "UserService" ) = userService
StringUtils.firstCharToLower( "UserServiceImpl" ) = userServiceImpl
rawString - 需要处理的字符串public static String prefixToLower(String rawString, int index)
rawString - 需要处理的字符串index - 多少个字符(从左至右)public static String removePrefixAfterPrefixToLower(String rawString, int index)
StringUtils.removePrefixAfterPrefixToLower( "isUser", 2 ) = user
StringUtils.removePrefixAfterPrefixToLower( "isUserInfo", 2 ) = userInfo
rawString - 需要处理的字符串index - 删除多少个字符(从左至右)public static String camelToHyphen(String input)
StringUtils.camelToHyphen( "managerAdminUserService" ) = manager-admin-user-service
input - ignorepublic static boolean containsLowerCase(String s)
@Deprecated public static String removeWordWithComma(String s, String p)
s - 原字符串p - 移除的单词Copyright © 2020. All rights reserved.