refactor: 优化驼峰转下划线逻辑

This commit is contained in:
zhouhao
2024-04-03 13:56:11 +08:00
parent a864748b02
commit 5080e8324e
2 changed files with 15 additions and 1 deletions

View File

@@ -17,7 +17,10 @@ public class QueryHelperUtils {
for (int i = 0, len = col.length(); i < len; i++) {
char c = col.charAt(i);
if (Character.isUpperCase(c)) {
builder.append('_').append(Character.toLowerCase(c));
if (i != 0) {
builder.append('_');
}
builder.append(Character.toLowerCase(c));
} else {
builder.append(c);
}

View File

@@ -15,5 +15,16 @@ class QueryHelperUtilsTest {
assertEquals("ruownum_",QueryHelperUtils.toHump("RUOWNUM_"));
}
@Test
void testToSnake(){
assertEquals("test_name",QueryHelperUtils.toSnake("testName"));
assertEquals("test_name",QueryHelperUtils.toSnake("TestName"));
}
}