diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..21ceffc2748c2bb7a8c1fcdbd00c3c53d89ef9b8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,40 @@
+*.class
+*.log
+*.ctxt
+.mtj.tmp/
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+hs_err_pid*
+replay_pid*
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+.mvn/wrapper/maven-wrapper.jar
+.project
+.classpath
+.idea/**/*
+cmake-build-*/
+.idea/**/mongoSettings.xml
+*.iws
+out/
+.idea_modules/
+atlassian-ide-plugin.xml
+.idea/replstate.xml
+.idea/sonarlint/
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+.idea/httpRequests
+.idea/caches/build_file_checksums.ser
diff --git a/pom.xml b/pom.xml
index 46451b27881becf2486a4045b743b291224caa33..0c0fcb5ceec45b5ad85ccc5edf27e2a0f3be6a3e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,6 +16,7 @@
1.7.26
3.5.1
2.5.10
+ 5.9.3
@@ -38,6 +39,13 @@
${mybatis-plus.version}
provided
+
+
+ org.junit.jupiter
+ junit-jupiter
+ ${junit.version}
+ test
+
@@ -78,9 +86,6 @@
org.apache.maven.plugins
maven-surefire-plugin
2.12.4
-
- true
-
org.apache.maven.plugins
diff --git a/src/main/java/club/kingon/sql/builder/util/SqlNameUtils.java b/src/main/java/club/kingon/sql/builder/util/SqlNameUtils.java
index f04e7f6479bc6af663545bb6ca5c17c1c92377bc..29d8cde8e4f4fe98a946de67e43f9dd87afa94dc 100644
--- a/src/main/java/club/kingon/sql/builder/util/SqlNameUtils.java
+++ b/src/main/java/club/kingon/sql/builder/util/SqlNameUtils.java
@@ -25,7 +25,7 @@ public class SqlNameUtils {
public static String handleName(String name) {
if (GlobalConfig.OPEN_STRICT_MODE && name != null) {
- return Arrays.stream(name.split("\\.")).map(SqlNameUtils::handleStrictName).collect(Collectors.joining("."));
+ return Arrays.stream(name.split("\\.")).map(String::trim).map(SqlNameUtils::handleStrictName).collect(Collectors.joining("."));
}
return name;
}
@@ -34,8 +34,8 @@ public class SqlNameUtils {
if (!"*".equals(name) && !name.contains("(")) {
if (name.contains(",")) {
return Arrays.stream(name.split(",")).map(String::trim).map(SqlNameUtils::handleName).collect(Collectors.joining(", "));
- } else if (name.contains("as")) {
- String[] columnAndAlias = name.split("as");
+ } else if (name.matches(".*\\s+as\\s+.*")) {
+ String[] columnAndAlias = name.split("\\s+as\\s+");
return handleName(columnAndAlias[0].trim()) + " as " + handleName(columnAndAlias[1].trim());
} else if (name.startsWith("`") || name.contains("->")) {
return name;
diff --git a/src/test/java/club/kingon/sql/builder/util/SqlNameUtilsTest.java b/src/test/java/club/kingon/sql/builder/util/SqlNameUtilsTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..1dc2e6a5ef1c40fe1e428d8711a9588feef22ab9
--- /dev/null
+++ b/src/test/java/club/kingon/sql/builder/util/SqlNameUtilsTest.java
@@ -0,0 +1,35 @@
+package club.kingon.sql.builder.util;
+
+import club.kingon.sql.builder.config.GlobalConfig;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class SqlNameUtilsTest {
+ @BeforeEach
+ void setUp() {
+ GlobalConfig.OPEN_STRICT_MODE = true;
+ }
+
+ @Test
+ void testHandleName() {
+ assertEquals("*", SqlNameUtils.handleName("*"));
+ assertEquals("*", SqlNameUtils.handleName(" * "));
+ assertEquals("`table`.*", SqlNameUtils.handleName("table.*"));
+ assertEquals("`table`.*", SqlNameUtils.handleName("`table`.*"));
+ assertEquals("`table`.*", SqlNameUtils.handleName(" table.* "));
+ assertEquals("`table`.`field`", SqlNameUtils.handleName("table.field"));
+ assertEquals("`table`.`field`", SqlNameUtils.handleName("`table`.`field`"));
+ assertEquals("`table`.`field`", SqlNameUtils.handleName(" table.field "));
+ assertEquals("`table` as `table1`", SqlNameUtils.handleName("table as table1"));
+ assertEquals("`table` as `table1`", SqlNameUtils.handleName("`table` as `table1`"));
+ assertEquals("`table` as `table1`", SqlNameUtils.handleName(" table as table1 "));
+ assertEquals("`task_table` as `task`", SqlNameUtils.handleName("task_table as task"));
+ assertEquals("`task`", SqlNameUtils.handleName("task"));
+ assertEquals("`task`", SqlNameUtils.handleName("`task`"));
+ assertEquals("`task`", SqlNameUtils.handleName(" task "));
+ assertEquals("`as`", SqlNameUtils.handleName("as"));
+ assertEquals("`as`", SqlNameUtils.handleName(" as "));
+ }
+}
\ No newline at end of file