锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
]]>
List dwVoListInTab = this.prodService.getPicTabVOList(picId);
List dwNameListInTab = new ArrayList();
for (PrdTabVO dwVo : dwVoListInTab) {
String dwName = this.prodService.cvtTabNo2DWName(useProdNo, picId,
dwVo.getCTabNo());
dwNameListInTab.add(dwName);
dwNameMap.put(dwVo.getCNmeEn(), dwName);
}
((List)plyDwNameList).addAll(dwNameListInTab);
String dwNameListStr = "['" + StringUtils.join(dwNameListInTab.toArray(), "','") + "']";
鍏跺畠錛?br />
StringUtils.join(new String[]{"cat","dog","carrot","leaf","door"}, ":")
// cat:dog:carrot:leaf:door
2銆丼tringUtils.isNotEmpty //Checks if a String is not empty ("") and not null.
if (StringUtils.isNotEmpty(onload))
onload = sub.replace(onload);
else {
onload = "";
}
public String replace(char oldChar,char newChar)榪斿洖涓涓柊鐨勫瓧絎︿覆錛屽畠鏄氳繃鐢?newChar 鏇?/span>鎹㈡瀛楃涓蹭腑鍑虹幇鐨勬墍鏈?oldChar 寰楀埌鐨勩?
濡傛灉 oldChar 鍦ㄦ String 瀵硅薄琛ㄧず鐨勫瓧絎﹀簭鍒椾腑娌℃湁鍑虹幇錛屽垯榪斿洖瀵規 String 瀵硅薄鐨勫紩鐢ㄣ?br />
3銆丼tringUtils.equals //StringUtils.equals(null, null) = true
if (!StringUtils.equals(prodKindNo, "00")) {
}
4銆丼tringUtils.isBlank //Checks if a String is whitespace, empty ("") or null.
if (StringUtils.isBlank(taskId))
jsBuffer.append("var taskId='';\n");
else {
jsBuffer.append("var taskId='" + taskId + "';\n");
}
5銆丼tringUtils.leftPad(String str, int size,String padStr) --宸﹀~鍏?br />
//鎶曚繚騫村害銆愪繚闄╄搗鏈?- 鍒濈櫥騫存湀銆?鍗曚綅錛氬勾
String ply_year = StringUtils.leftPad(String.valueOf(DateUtils.compareYear(regDate,base.getTInsrncBgnTm())), 2, '0');
/**
4260 * <p>Left pad a String with a specified String.</p>
4261 *
4262 * <p>Pad to a size of <code>size</code>.</p>
4263 *
4264 * <pre>
4265 * StringUtils.leftPad(null, *, *) = null
4266 * StringUtils.leftPad("", 3, "z") = "zzz"
4267 * StringUtils.leftPad("bat", 3, "yz") = "bat"
4268 * StringUtils.leftPad("bat", 5, "yz") = "yzbat"
4269 * StringUtils.leftPad("bat", 8, "yz") = "yzyzybat"
4270 * StringUtils.leftPad("bat", 1, "yz") = "bat"
4271 * StringUtils.leftPad("bat", -1, "yz") = "bat"
4272 * StringUtils.leftPad("bat", 5, null) = " bat"
4273 * StringUtils.leftPad("bat", 5, "") = " bat"
4274 * </pre>
4275 *
4276 * @param str the String to pad out, may be null
4277 * @param size the size to pad to
4278 * @param padStr the String to pad with, null or empty treated as single space
4279 * @return left padded String or original String if no padding is necessary,
4280 * <code>null</code> if null String input
4281 */
4282 public static String leftPad(String str, int size, String padStr) {
4283 if (str == null) {
4284 return null;
4285 }
4286 if (isEmpty(padStr)) {
4287 padStr = " ";
4288 }
4289 int padLen = padStr.length();
4290 int strLen = str.length();
4291 int pads = size - strLen;
4292 if (pads <= 0) {
4293 return str; // returns original String when possible
4294 }
4295 if (padLen == 1 && pads <= PAD_LIMIT) {
4296 return leftPad(str, size, padStr.charAt(0));
4297 }
4298
4299 if (pads == padLen) {
4300 return padStr.concat(str);
4301 } else if (pads < padLen) {
4302 return padStr.substring(0, pads).concat(str);
4303 } else {
4304 char[] padding = new char[pads];
4305 char[] padChars = padStr.toCharArray();
4306 for (int i = 0; i < pads; i++) {
4307 padding[i] = padChars[i % padLen];
4308 }
4309 return new String(padding).concat(str);
4310 }
4311 }
---------------------------------------------
璇﹁錛歨ttp://commons.apache.org/lang/api/org/apache/commons/lang/StringUtils.html
isEmpty
public static boolean isEmpty(CharSequence str)
Checks if a String is empty ("") or null.
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the String. That
functionality is available in isBlank().
Parameters:
str - the String to check, may be null
Returns:
true if the String is empty or null
isNotEmpty
public static boolean isNotEmpty(CharSequence str)
Checks if a String is not empty ("") and not null.
StringUtils.isNotEmpty(null) = false
StringUtils.isNotEmpty("") = false
StringUtils.isNotEmpty(" ") = true
StringUtils.isNotEmpty("bob") = true
StringUtils.isNotEmpty(" bob ") = true
Parameters:
str - the String to check, may be null
Returns:
true if the String is not empty and not null
isBlank
public static boolean isBlank(CharSequence str)
Checks if a String is whitespace, empty ("") or null.
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
Parameters:
str - the String to check, may be null
Returns:
true if the String is null, empty or whitespace
Since:
2.0
isNotBlank
public static boolean isNotBlank(CharSequence str)
Checks if a String is not empty (""), not null and not whitespace only.
StringUtils.isNotBlank(null) = false
StringUtils.isNotBlank("") = false
StringUtils.isNotBlank(" ") = false
StringUtils.isNotBlank("bob") = true
StringUtils.isNotBlank(" bob ") = true
Parameters:
str - the String to check, may be null
Returns:
true if the String is not empty and not null and not whitespace
Since:
2.0
trim
public static String trim(String str)
Removes control characters (char <= 32) from both ends of this String, handling null by
returning null.
The String is trimmed using String.trim(). Trim removes start and end characters <= 32.
To strip whitespace use strip(String).
To trim your choice of characters, use the strip(String, String) methods.
StringUtils.trim(null) = null
StringUtils.trim("") = ""
StringUtils.trim(" ") = ""
StringUtils.trim("abc") = "abc"
StringUtils.trim(" abc ") = "abc"
Parameters:
str - the String to be trimmed, may be null
Returns:
the trimmed string, null if null String input
trimToNull
public static String trimToNull(String str)
Removes control characters (char <= 32) from both ends of this String returning null if
the String is empty ("") after the trim or if it is null.
The String is trimmed using String.trim(). Trim removes start and end characters <= 32.
To strip whitespace use stripToNull(String).
StringUtils.trimToNull(null) = null
StringUtils.trimToNull("") = null
StringUtils.trimToNull(" ") = null
StringUtils.trimToNull("abc") = "abc"
StringUtils.trimToNull(" abc ") = "abc"
Parameters:
str - the String to be trimmed, may be null
Returns:
the trimmed String, null if only chars <= 32, empty or null String input
Since:
2.0
trimToEmpty
public static String trimToEmpty(String str)
Removes control characters (char <= 32) from both ends of this String returning an empty
String ("") if the String is empty ("") after the trim or if it is null.
The String is trimmed using String.trim(). Trim removes start and end characters <= 32.
To strip whitespace use stripToEmpty(String).
StringUtils.trimToEmpty(null) = ""
StringUtils.trimToEmpty("") = ""
StringUtils.trimToEmpty(" ") = ""
StringUtils.trimToEmpty("abc") = "abc"
StringUtils.trimToEmpty(" abc ") = "abc"
Parameters:
str - the String to be trimmed, may be null
Returns:
the trimmed String, or an empty String if null input
Since:
2.0
equals
public static boolean equals(String str1,
String str2)
Compares two Strings, returning true if they are equal.
nulls are handled without exceptions. Two null references are considered to be equal. The
comparison is case sensitive.
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
Parameters:
str1 - the first String, may be null
str2 - the second String, may be null
Returns:
true if the Strings are equal, case sensitive, or both null
See Also:
String.equals(Object)
startsWith
public static boolean startsWith(String str,
String prefix)
Check if a String starts with a specified prefix.
nulls are handled without exceptions. Two null references are considered to be equal. The
comparison is case sensitive.
StringUtils.startsWith(null, null) = true
StringUtils.startsWith(null, "abc") = false
StringUtils.startsWith("abcdef", null) = false
StringUtils.startsWith("abcdef", "abc") = true
StringUtils.startsWith("ABCDEF", "abc") = false
Parameters:
str - the String to check, may be null
prefix - the prefix to find, may be null
Returns:
true if the String starts with the prefix, case sensitive, or both null
Since:
2.4
See Also:
String.startsWith(String)
1.鍘婚櫎灝鵑儴鎹㈣絎︼紝浣跨敤鍑芥暟錛?/span>StringUtils.chomp(testString)
鍑芥暟浠嬬粛:鍘婚櫎testString灝鵑儴鐨勬崲琛岀
渚嬬▼:
String input = "Hello\n";
System.out.println( StringUtils.chomp( input ));
String input2 = "Another test\r\n";
System.out.println( StringUtils.chomp( input2 ));
杈撳嚭濡備笅:
Hello
Another test
2.鍒ゆ柇瀛楃涓插唴瀹圭殑綾誨瀷錛屽嚱鏁頒粙緇嶏細
StringUtils.isNumeric( testString ) :濡傛灉testString鍏ㄧ敱鏁板瓧緇勬垚榪斿洖True
StringUtils.isAlpha( testString ) :濡傛灉testString鍏ㄧ敱瀛楁瘝緇勬垚榪斿洖True
StringUtils.isAlphanumeric( testString ) :濡傛灉testString鍏ㄧ敱鏁板瓧鎴栨暟瀛楃粍鎴愯繑鍥濼rue
StringUtils.isAlphaspace( testString ) :濡傛灉testString鍏ㄧ敱瀛楁瘝鎴栫┖鏍肩粍鎴愯繑鍥濼rue
渚嬬▼:
String state = "Virginia";
System.out.println( "Is state number? " + StringUtils.isNumeric(state ) );
System.out.println( "Is state alpha? " + StringUtils.isAlpha( state ));
System.out.println( "Is state alphanumeric? " +StringUtils.isAlphanumeric( state ) );
System.out.println( "Is state alphaspace? " + StringUtils.isAlphaSpace( state ) );
杈撳嚭濡備笅:
Is state number? false
Is state alpha? true
Is state alphanumeric? true
Is state alphaspace? true
3.鏌ユ壘宓屽瀛楃涓詫紝浣跨敤鍑芥暟錛?br />
StringUtils.substringBetween(testString,header,tail)
鍑芥暟浠嬬粛錛氬湪testString涓彇寰梙eader鍜宼ail涔嬮棿鐨勫瓧絎︿覆銆備笉瀛樺湪鍒欒繑鍥炵┖
渚嬬▼錛?br />
String htmlContent = "ABC1234ABC4567";
System.out.println(StringUtils.substringBetween(htmlContent, "1234", "4567"));
System.out.println(StringUtils.substringBetween(htmlContent, "12345", "4567"));
杈撳嚭濡備笅錛?br />
ABC
null
4.棰犲掑瓧絎︿覆錛屼嬌鐢ㄥ嚱鏁幫細StringUtils.reverse(testString)
鍑芥暟浠嬬粛:寰楀埌testString涓瓧絎﹂鍊掑悗鐨勫瓧絎︿覆
渚嬬▼:
System.out.println( StringUtils.reverse("ABCDE"));
杈撳嚭濡備笅:
EDCBA
5.閮ㄥ垎鎴彇瀛楃涓詫紝浣跨敤鍑芥暟錛?/span>
StringUtils.substringBetween(testString,fromString,toString ):鍙栧緱涓ゅ瓧絎︿箣闂寸殑瀛楃涓?br />
StringUtils.substringAfter( ):鍙栧緱鎸囧畾瀛楃涓插悗鐨勫瓧絎︿覆
StringUtils.substringBefore( )錛氬彇寰楁寚瀹氬瓧絎︿覆涔嬪墠鐨勫瓧絎︿覆
StringUtils.substringBeforeLast( )錛氬彇寰楁渶鍚庝竴涓寚瀹氬瓧絎︿覆涔嬪墠鐨勫瓧絎︿覆
StringUtils.substringAfterLast( )錛氬彇寰楁渶鍚庝竴涓寚瀹氬瓧絎︿覆涔嬪悗鐨勫瓧絎︿覆
鍑芥暟浠嬬粛錛氫笂闈㈠簲璇ラ兘璁叉槑鐧戒簡鍚с?br />
渚嬬▼錛?br />
String formatted = " 25 * (30,40) [50,60] | 30";
System.out.print("N0: " + StringUtils.substringBeforeLast( formatted, "*" ) );
System.out.print(", N1: " + StringUtils.substringBetween( formatted, "(", "," ) );
System.out.print(", N2: " + StringUtils.substringBetween( formatted, ",", ")" ) );
System.out.print(", N3: " + StringUtils.substringBetween( formatted, "[", "," ) );
System.out.print(", N4: " + StringUtils.substringBetween( formatted, ",", "]" ) );
System.out.print(", N5: " + StringUtils.substringAfterLast( formatted, "|" ) );
杈撳嚭濡備笅錛?br />
N0: 25 , N1: 30, N2: 40, N3: 50, N4: 40) [50,60, N5: 30
2銆丅eanUtils.copyProperties(java.lang.Object dest, java.lang.Object orig)
涓涓猙ean class鏈変袱涓疄渚?orig鍜宒est,灝唎rig涓殑鎴愬憳鍙橀噺鐨勫煎鍒剁粰dest,鍗沖皢宸茬粡瀛樺湪鐨刣est鍙樹負orig鐨勫壇鏈?涓嶣eanUtils.cloneBean(java.lang.object bean)鐨勫尯鍒氨鍦ㄤ簬鏄笉鏄渶瑕佸垱寤烘柊鐨勫疄渚嬩簡.
鍘熸枃濡備笅:Copy property values from the origin bean to the destination bean for all cases where the property names are the same.
3銆丅eanUtils.setProperty(java.lang.Object bean,java.lang.String name,java.lang.Object value)
榪欎釜鏂規硶綆鍗曠殑璇村氨鏄皢bean涓殑鎴愬憳鍙橀噺name璧嬪間負value.
BeanUtils.populate(java.lang.Object bean, java.util.Map properties)
浣跨敤涓涓猰ap涓篵ean璧嬪?璇ap涓殑key鐨勫悕縐頒笌bean涓殑鎴愬憳鍙橀噺鍚嶇О鐩稿搴?娉ㄦ剰:鍙湁鍦╧ey鍜屾垚鍛樺彉閲忓悕縐板畬鍏ㄥ搴旂殑鏃跺?populate鏈哄埗鎵嶅彂鐢熶綔鐢?浣嗘槸鍦ㄦ暟閲忎笂娌℃湁浠諱綍瑕佹眰,濡俶ap涓殑key濡傛灉鏄垚鍛樺彉閲忓悕縐扮殑瀛愰泦,閭d箞鎴愬憳鍙橀噺涓湁鐨勮宮ap涓笉鍖呭惈鐨勯」灝嗕細淇濈暀榛樿鍊?鍚屾牱,濡傛灉鎴愬憳鍙橀噺鏄痬ap涓璳ey鐨勫瓙闆?閭d箞澶氫綑鐨刱ey涓嶄細瀵筽opulate鐨勭粨鏋滀駭鐢熶換浣曞獎鍝?鎭?緇撴灉灝辨槸populate鍙拡瀵筸ap涓璳ey鍚嶇О闆嗗悎涓巄ean涓垚鍛樺彉閲忓悕縐伴泦鍚堢殑浜ら泦浜х敓浣滅敤銆?/span>
4銆丅eanUtils.getArrayProperty(java.lang.Object bean,java.lang.String name)
鑾峰彇bean涓暟緇勬垚鍛樺彉閲?灞炴?鐨勫?
濡傛灉鎴戜滑鎸囧畾鐨刵ame涓嶆槸鏁扮粍綾誨瀷鐨勬垚鍛樺彉閲?緇撴灉浼氬浣?浼氫笉浼氭姏鍑虹被鍨嬮敊璇殑exception鍛?鍥炵瓟鏄笉浼?浠嶇劧浼氳繑鍥炰竴涓猄tring鐨勬暟緇?鏁扮粍鐨勭涓欏瑰氨鏄痭ame瀵瑰簲鐨勫?濡傛灉涓?/p>
鏄疭tring綾誨瀷鐨勮瘽,JVM浼氳嚜鍔ㄧ殑璋冪敤toString()鏂規硶鐨?.
BeanUtils.getIndexedProperty(java.lang.Object bean,java.lang.String name)
BeanUtils.getIndexedProperty(java.lang.Object bean,java.lang.String name,int index)
榪欎袱涓柟娉曢兘鏄幏鍙栨暟緇勬垚鍛樺彉閲?灞炴?涓殑鍗曚竴鍏冪礌鍊肩殑鏂規硶.
姣斿,鎴戞兂寰楀埌SampleObject涓瓀ords[1]鐨勫?鐢ㄦ硶濡備笅:
BeanUtils.getIndexedProperty(sampleOjbectInstance,"words[1]");
BeanUtils.getIndexedProperty(sampleOjbectInstance,"words",1);
BeanUtils.getMappedProperty(java.lang.Object bean,java.lang.String name)
BeanUtils.getMappedProperty(java.lang.Object bean,java.lang.String name,java.lang.String key)
BeanUtils.describe(java.lang.Object bean)
灝嗕竴涓猙ean浠ap鐨勫艦寮忓睍紺恒?br />