用来将字符串在驼峰风格跟下划线风格之间切换。对于一般人可能没用,对于写orm框架的人有点作用。
例子:
company_name -> companyName
添加以下依赖到pom.xml
<dependency> <groupId>org.crazycake</groupId> <artifactId>camel-name-utils</artifactId> <version>1.0.0-RELEASE</version> </dependency>
@Test public void testCamel2underscore() { String underscoreName = CamelNameUtils.camel2underscore("AaaBbb"); assertThat(underscoreName, is("aaa_bbb")); } @Test public void testUnderscore2camel() { String camelName = CamelNameUtils.underscore2camel("user_name"); assertThat(camelName,is("userName")); } @Test public void testCapitalize() { String capitalName = CamelNameUtils.capitalize("student"); assertThat(capitalName,is("Student")); }