Skip to content

Commit a2f4698

Browse files
committed
解决驼峰转下划线的错误,感谢 piggsoft 和 liufor 的PR
1 parent 4307683 commit a2f4698

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/main/java/tk/mybatis/mapper/util/StringUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ public static String camelhumpToUnderline(String str) {
9292
for (int i = 0; i < size; i++) {
9393
c = chars[i];
9494
if (isUppercaseAlpha(c)) {
95-
sb.append('_').append(c);
95+
sb.append('_').append(toLowerAscii(c));
9696
} else {
97-
sb.append(toUpperAscii(c));
97+
sb.append(c);
9898
}
9999
}
100100
return sb.charAt(0) == '_' ? sb.substring(1) : sb.toString();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package tk.mybatis.mapper.helper;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import tk.mybatis.mapper.util.StringUtil;
6+
7+
/**
8+
* @author liuzh_3nofxnp
9+
* @since 2016-08-29 22:02
10+
*/
11+
public class CamelCaseTest {
12+
13+
@Test
14+
public void testCamelhumpToUnderline() {
15+
Assert.assertEquals("user_id", StringUtil.camelhumpToUnderline("userId"));
16+
Assert.assertEquals("sys_user", StringUtil.camelhumpToUnderline("sysUser"));
17+
Assert.assertEquals("sys_user_role", StringUtil.camelhumpToUnderline("sysUserRole"));
18+
Assert.assertEquals("s_function", StringUtil.camelhumpToUnderline("sFunction"));
19+
}
20+
}

0 commit comments

Comments
 (0)