Discuss / Java / 交作业~

交作业~

Topic source

于你可樂

#1 Created at ... [Delete] [Delete and Lock User]

请多指教~

    static String buildSelectSql(String table, String[] fields) {
        // TODO:
        var s = String.join(", ", fields);
        String columns = s.toString();
        String selectSql = "SELECT %s FROM %s".formatted(columns, table);
        return selectSql;
    }

于你可樂

#2 Created at ... [Delete] [Delete and Lock User]

使用StringJoiner对象:

    static String buildSelectSql(String table, String[] fields) {
        // TODO:
        var sj = new StringJoiner(", ");
        for (String c : fields) {
            sj.add(c);
        }
        String columns = sj.toString();
        String selectSql = "SELECT %s FROM %s".formatted(columns, table);
        return selectSql;
    }

高谦05

#3 Created at ... [Delete] [Delete and Lock User]

妙啊

Young-96

#4 Created at ... [Delete] [Delete and Lock User]

学习了

优秀


  • 1

Reply