|
@@ -1,6 +1,7 @@
|
|
|
package com.its.op;
|
|
|
|
|
|
import lombok.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
|
|
|
@@ -13,9 +14,75 @@ import java.util.Optional;
|
|
|
import java.util.function.*;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
+@Slf4j
|
|
|
@ActiveProfiles(profiles = "dev")
|
|
|
public class UtilTest {
|
|
|
|
|
|
+ public String stringToCamelStyle(String str) {
|
|
|
+ if (str != null) {
|
|
|
+ if (str.contains("_")) {
|
|
|
+ str = str.toLowerCase();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append(String.valueOf(str.charAt(0)).toUpperCase());
|
|
|
+ log.info("1: {}", sb);
|
|
|
+ for (int i = 1; i < str.length(); i++) {
|
|
|
+ char c = str.charAt(i);
|
|
|
+ if (c != '_') {
|
|
|
+ sb.append(c);
|
|
|
+ } else {
|
|
|
+ if (i + 1 < str.length()) {
|
|
|
+ sb.append(String.valueOf(str.charAt(i + 1)).toUpperCase());
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ } else {
|
|
|
+ String firstChar = String.valueOf(str.charAt(0)).toUpperCase();
|
|
|
+ String otherChars = str.substring(1);
|
|
|
+ log.info("1: {}, {}", firstChar, otherChars);
|
|
|
+ return firstChar + otherChars;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ public String stringToCamelStyle2(String str) {
|
|
|
+ if (str != null) {
|
|
|
+ if (str.contains("_")) {
|
|
|
+ str = str.toLowerCase();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append(String.valueOf(str.charAt(0)).toLowerCase());
|
|
|
+ log.info("1: {}", sb);
|
|
|
+ for (int i = 1; i < str.length(); i++) {
|
|
|
+ char c = str.charAt(i);
|
|
|
+ if (c != '_') {
|
|
|
+ sb.append(c);
|
|
|
+ } else {
|
|
|
+ if (i + 1 < str.length()) {
|
|
|
+ sb.append(String.valueOf(str.charAt(i + 1)).toUpperCase());
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ } else {
|
|
|
+ String firstChar = String.valueOf(str.charAt(0)).toLowerCase();
|
|
|
+ String otherChars = str.substring(1).toLowerCase();
|
|
|
+ log.info("1: {}, {}", firstChar, otherChars);
|
|
|
+ return firstChar + otherChars;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void test0() {
|
|
|
+ String column = "user_parent_name";
|
|
|
+ String result = stringToCamelStyle(column);
|
|
|
+ log.info("1: {}", result);
|
|
|
+ result = stringToCamelStyle2(column);
|
|
|
+ log.info("2: {}", result);
|
|
|
+ }
|
|
|
@Test
|
|
|
void test1() {
|
|
|
ZonedDateTime a = ZonedDateTime.now();
|