名命规则转换工具
示例代码
package demo;
import com.google.common.base.CaseFormat;
import com.google.common.base.Converter;
/**
* 名命规则转换
* @author ChenWei
* @email 582900710@qq.com
* @date 2021年7月16日 下午4:09:36
*/
public class CaseFormatDemo {
/* 需要依赖的jar
* <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
</dependency>
*/
/* 提供的转换方法
* CaseFormat 以提供不同 ASCII 字符格式之间的转换,比如,编程语言的命名规范
* LOWER_CAMEL => 小写驼峰
* LOWER_HYPHEN => 小写连字符
* LOWER_UNDERSCORE => 小写下划线
* UPPER_CAMEL => 大写驼峰
* UPPER_UNDERSCORE => 大写下划线
*/
public static void main(String[] args) {
//示例代码
//大驼峰 转 小写下划线
Converter<String, String> converterTo = CaseFormat.UPPER_CAMEL.converterTo(CaseFormat.LOWER_UNDERSCORE);
String convert = converterTo.convert(CaseFormatDemo.class.getSimpleName());
System.out.println(convert);
}
}