import com.google.common.base.CaseFormat;
import lombok.extern.slf4j.Slf4j;
/**
* <dependency>
* <groupId>com.google.guava</groupId>
* <artifactId>guava</artifactId>
* <version>23.0</version>
* </dependency>
*
* @Author niewj
* @Date 2019/12/28 15:05
* @Version 1.0
*/
@Slf4j
public class CamelCast {
public static void main(String[] args) {
// "test-data"->"testData" (小写连字符->小写驼峰)
log.info(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, "test-data"));
// "test_data"->"testData" (小写下划线->小写驼峰)
log.info(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "test_data"));
// "test_data"->"TestData" (小写下划线->大写驼峰)
log.info(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, "test_data"));
// "testData"->"test_data" (小写驼峰->小写下划线)
log.info(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "testData"));
// "TestData" -> "test_data" (大写驼峰->小写下划线)
log.info(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "TestData"));
// "testData"-> "test-data" (小写驼峰->小写连字符)
log.info(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, "testData"));
// "TEST_DATA"-> "testData" (大写下划线->小写驼峰)
log.info(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "TEST_DATA"));
// "TEST_DATA"-> test-data (大写下划线->小写连字符)
log.info(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, "TEST_DATA"));
}
}
- camel=骆驼
- hyphen=连字符
- underscore=下划线
- hyphen和dash区别
连字符: non-smoker 中是 hyphen
波折号: 1928-2008 中是 dash
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。