代码片段:在数据库COLUMN_NAME和Java类attrName之间互转

// firstName => FIRST_NAME
	private static String attrNameToColumnName(String attName) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < attName.length(); i++) {
			char c = attName.charAt(i);
			if (!(c <= 'z' && c >= 'a')) {
				sb.append("_");
			}
			sb.append(c);
		}
		return sb.toString().toUpperCase();
	}
//FIRST_NAME => firstName 
	private static String columnNameToAttrName(String attrName) {
		String capitalized = WordUtils.capitalize(attrName.toLowerCase(), new char[] { '_' });
		String lineRemoved = StringUtils.remove(capitalized, "_");
		return StringUtils.uncapitalize(lineRemoved);
	}

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.