From 3723ef3de94baf76ffbcdd569b1450330beb9c79 Mon Sep 17 00:00:00 2001 From: darren Date: Fri, 29 Oct 2021 17:21:40 +0800 Subject: [PATCH] fix https://github.com/mybatis-mapper/mapper/issues/13 (cherry picked from commit cadd366e052b04ba7a0458599fd806998f8416c4) --- .../main/java/io/mybatis/mapper/example/Example.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mapper/src/main/java/io/mybatis/mapper/example/Example.java b/mapper/src/main/java/io/mybatis/mapper/example/Example.java index b92cb13..302c607 100644 --- a/mapper/src/main/java/io/mybatis/mapper/example/Example.java +++ b/mapper/src/main/java/io/mybatis/mapper/example/Example.java @@ -22,6 +22,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.regex.Matcher; + +import static io.mybatis.provider.EntityTable.DELIMITER; /** * 通用的 Example 查询对象 @@ -130,7 +133,13 @@ public Example selectColumns(Fn... fns) { if (column.equals(field) || entityColumn.entityTable().useResultMaps()) { selectColumns += column; } else { - selectColumns += column + " AS " + field; + Matcher matcher = DELIMITER.matcher(column); + //eg: mysql `order` == field order | sqlserver [order] == field order + if (matcher.find() && field.equals(matcher.group(1))) { + selectColumns += column; + } else { + selectColumns += column + " AS " + field; + } } } return this;