diff --git a/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/query/QueryAnalyzerImpl.java b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/query/QueryAnalyzerImpl.java index 285e722c4..486773619 100644 --- a/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/query/QueryAnalyzerImpl.java +++ b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/query/QueryAnalyzerImpl.java @@ -113,6 +113,11 @@ private Map getColumnMappings() { Column col = new Column(column.getName(), column.getAlias(), select.table.alias, column.metadata); columnMappings.put(entry.getKey(), col); columnMappings.put(select.table.alias + "." + entry.getKey(), col); + + if (!(column instanceof ExpressionColumn) && column.metadata != null) { + columnMappings.put(column.metadata.getName(), col); + columnMappings.put(select.table.alias + "." + column.metadata.getName(), col); + } } for (Column column : select.getColumnList()) { @@ -191,7 +196,7 @@ private static SelectBody parse(String sql) { } private String parsePlainName(String name) { - if (name == null || name.length() == 0) { + if (name == null || name.isEmpty()) { return null; } char firstChar = name.charAt(0); @@ -524,10 +529,11 @@ public SqlFragments createTermFragments(QueryAnalyzerImpl impl, Term term) { if (col.metadata == null) { metadata = table.metadata; } + String colName = col.metadata != null ? col.metadata.getName() : col.name; return metadata .findFeature(createFeatureId(term.getTermType())) .map(feature -> feature.createFragments( - table.alias + "." + dialect.quote(col.name, col.metadata != null), col.metadata, term)) + table.alias + "." + dialect.quote(colName, col.metadata != null), col.metadata, term)) .orElse(EmptySqlFragments.INSTANCE); } } diff --git a/hsweb-commons/hsweb-commons-crud/src/test/java/org/hswebframework/web/crud/query/DefaultQueryHelperTest.java b/hsweb-commons/hsweb-commons-crud/src/test/java/org/hswebframework/web/crud/query/DefaultQueryHelperTest.java index 3413a4844..e956eb44f 100644 --- a/hsweb-commons/hsweb-commons-crud/src/test/java/org/hswebframework/web/crud/query/DefaultQueryHelperTest.java +++ b/hsweb-commons/hsweb-commons-crud/src/test/java/org/hswebframework/web/crud/query/DefaultQueryHelperTest.java @@ -65,14 +65,17 @@ public void testInner() { .insert("s_test") .value("id", "inner-test") .value("name", "inner") + .value("testName","inner") .value("age", 31) .execute() .sync(); - helper.select("select age,count(1) c from ( select name,age from s_test ) a group by age ", 0) + helper.select("select age,count(1) c from ( select *,'1' as x from s_test ) a group by age ", 0) .where(dsl -> dsl - .is("a.name", "inner") + .is("x", "1") + .is("name", "inner") + .is("a.testName", "inner") .is("age", 31)) .fetchPaged(0, 10) .doOnNext(v -> System.out.println(JSON.toJSONString(v, SerializerFeature.PrettyFormat)))