Skip to content

Commit

Permalink
1,添加对表格的默认排序。
Browse files Browse the repository at this point in the history
2,修复了由表名转PO对象类时,一些骆驼法则使用上,造成大小写的异常问题。如,表名:TUserAccount ,之前转换为了:Tuseraccount。这并非想要的,理想应该转为:TUserAccount
  • Loading branch information
trying-cui committed Jul 31, 2018
1 parent d11e88a commit 45706d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/zzg/mybatis/generator/util/DbUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public static List<String> getTableNames(DatabaseConfig config) throws Exception
while (rs.next()) {
tables.add(rs.getString(3));
}

if (tables.size()>1) {
Collections.sort(tables);
}
return tables;
} finally {
connection.close();
Expand Down
30 changes: 18 additions & 12 deletions src/main/java/com/zzg/mybatis/generator/util/MyStringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@ public class MyStringUtils {
*/
public static String dbStringToCamelStyle(String str) {
if (str != null) {
str = str.toLowerCase();
StringBuilder sb = new StringBuilder();
sb.append(String.valueOf(str.charAt(0)).toUpperCase());
for (int i = 1; i < str.length(); i++) {
char c = str.charAt(i);
if (c != '_') {
sb.append(c);
} else {
if (i + 1 < str.length()) {
sb.append(String.valueOf(str.charAt(i + 1)).toUpperCase());
i++;
if (str.contains("_")) {
str = str.toLowerCase();
StringBuilder sb = new StringBuilder();
sb.append(String.valueOf(str.charAt(0)).toUpperCase());
for (int i = 1; i < str.length(); i++) {
char c = str.charAt(i);
if (c != '_') {
sb.append(c);
} else {
if (i + 1 < str.length()) {
sb.append(String.valueOf(str.charAt(i + 1)).toUpperCase());
i++;
}
}
}
return sb.toString();
} else {
String firstChar = String.valueOf(str.charAt(0)).toUpperCase();
String otherChars = str.substring(1);
return firstChar + otherChars;
}
return sb.toString();
}
return null;
}
Expand Down

0 comments on commit 45706d5

Please sign in to comment.