Explorar o código

refactor(h2db): 优化 SQL 查询语句

- 使用 DialectUtil.wrapField() 方法封装字段名,提高代码可读性和可维护性
- 采用 String.format() 构建 SQL 语句,提升代码整洁度
-保留原始逻辑的注释,便于理解和回退
bwcx_jzy hai 5 meses
pai
achega
1e23960c58

+ 3 - 1
modules/server/src/main/java/org/dromara/jpom/service/h2db/BaseDbService.java

@@ -102,7 +102,9 @@ public abstract class BaseDbService<T extends BaseDbModel> extends BaseDbCommonS
      * @return list
      */
     public List<String> listGroupName() {
-        String sql = "select groupName from " + this.getTableName() + " group by groupName";
+        String group = DialectUtil.wrapField("groupName");
+        String sql = String.format("select %s from %s group by %s", group, getTableName(), group);
+        //String sql = "select groupName from " + this.getTableName() + " group by groupName";
         return this.listGroupByName(sql, "groupName");
     }