Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化 columnAsProperty #1

Merged
merged 1 commit into from
Oct 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/main/java/io/mybatis/provider/EntityColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;

import static io.mybatis.provider.EntityTable.DELIMITER;

/**
* 实体中字段和列的对应关系接口,记录字段上提供的列信息
Expand Down Expand Up @@ -195,7 +198,14 @@ public String columnAsProperty() {
* @param prefix 指定前缀,需要自己提供"."
*/
public String columnAsProperty(String prefix) {
if (!Objects.equals(column(), property(prefix))) {
// 这里的column 和 property 的比较 应该是需要忽略界定符之后再比较
// eg: mysql 中 【`order`】 应该认为是 和 field 的 【order】 相同
String column = column();
Matcher matcher = DELIMITER.matcher(column());
if (matcher.find()) {
column = matcher.group(1);
}
if (!Objects.equals(column, property(prefix))) {
return column() + " AS " + property(prefix);
}
return column();
Expand Down