resultMap.append(property2Column(property));
resultMap.append("\" jdbcType=\"");
resultMap.append(javaType2jdbcType(javaType.toLowerCase()));
resultMap.append("\" property=\"");
resultMap.append(property);
resultMap.append("\" />\n");
}
resultMap.append("");
return resultMap.toString();
}
private static String property2Column(String property){
Matcher matcher = humpPattern.matcher(property);
StringBuffer sb = new StringBuffer();
while(matcher.find()){
matcher.appendReplacement(sb, "_"+matcher.group(0).toLowerCase());
}
matcher.appendTail(sb);
return sb.toString();
}
private static String javaType2jdbcType(String javaType){
if(javaType.contains("string")){
return "VARCHAR";
}else if(javaType.contains("boolean")){
return "BIT";
}else if(javaType.contains("byte")){
return "TINYINT";
}else if(javaType.contains("short")){
return "SMALLINT";
}else if(javaType.contains("int")){
return "INTEGER";
}else if(javaType.contains("long")){
return "BIGINT";
}else if(javaType.contains("double")){
return "DOUBLE";
}else if(javaType.contains("float")){
return "REAL";
}else if(javaType.contains("date")){
return "DATE";
}else if(javaType.contains("timestamp")){
return "TIMESTAMP";
}else if(javaType.contains("time")){
return "TIME";
}else if(javaType.contains("bigdecimal")){
return "DECIMAL";
}else{
return "未知类型";
}
}
}