一、代码
/**
* 截取指定长度的字符串
* @param str
* @param maxLength
* @return
*/
private static String substring(String str, Integer maxLength) {
if (StringUtils.isBlank(str)) {
return null;
}
str = str.trim();
if (null == maxLength || maxLength < 0) {
return str;
}
int length = str.length();
maxLength = maxLength > length ? length : maxLength;
return str.substring(0, maxLength);
}