Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30b23c0

Browse files
committed
commit update join支持@cast字段类型转换
1 parent 70f65fe commit 30b23c0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,8 +4847,20 @@ protected String concatJoinOn(@NotNull String sql, @NotNull String quote, @NotNu
48474847

48484848
String rt = on.getRelateType();
48494849
if (StringUtil.isEmpty(rt, false)) {
4850-
sql += (first ? ON : AND) + quote + jt + quote + "." + quote + on.getKey() + quote + (isNot ? " != " : " = ")
4851-
+ quote + getSQLTableWithAlias(on.getTargetTable(), on.getTargetAlias()) + quote + "." + quote + on.getTargetKey() + quote;
4850+
//解决join不支持@cast问题
4851+
Map castMap = j.getJoinConfig().getCast();
4852+
if (castMap.isEmpty()) {
4853+
sql += (first ? ON : AND) + quote + jt + quote + "." + quote + on.getKey() + quote + (isNot ? " != " : " = ")
4854+
+ quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote;
4855+
} else {
4856+
String leftTableRelationSql = quote + jt + quote + "." + quote + on.getKey() + quote;
4857+
Object castValueType = castMap.get(on.getOriginKey());
4858+
if (castValueType != null) {
4859+
leftTableRelationSql = "CAST(" + leftTableRelationSql + " AS " + castValueType + ")";
4860+
}
4861+
sql += (first ? ON : AND) + leftTableRelationSql + (isNot ? " != " : " = ")
4862+
+ quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote;
4863+
}
48524864
}
48534865
else {
48544866
onJoinComplexRelation(sql, quote, j, jt, onList, on);

0 commit comments

Comments
 (0)