add nullIfBlank

This commit is contained in:
Looly
2024-12-20 18:02:52 +08:00
parent a5d5af1b8f
commit 274409c416

View File

@@ -153,6 +153,18 @@ public class CharSequenceUtil extends StrValidator {
return isEmpty(str) ? null : str; return isEmpty(str) ? null : str;
} }
/**
* 当给定字符串为空字符串时,转换为{@code null}
*
* @param <T> 字符串类型
* @param str 被转换的字符串
* @return 转换后的字符串
* @since 6.0.0
*/
public static <T extends CharSequence> T nullIfBlank(final T str) {
return isBlank(str) ? null : str;
}
/** /**
* <p>如果给定字符串为{@code null}返回默认值 * <p>如果给定字符串为{@code null}返回默认值
* <pre>{@code * <pre>{@code