Discuss / Java / 打卡作业,互相学习,关注微信公众号【程序员明明】

打卡作业,互相学习,关注微信公众号【程序员明明】

Topic source

明明love0

#1 Created at ... [Delete] [Delete and Lock User]
public class Main {

	public static void main(String[] args) {
		String[] fields = { "name", "position", "salary" };
		String table = "employee";
		String select = buildSelectSql(table, fields);
		System.out.println(select);
		System.out.println("SELECT name, position, salary FROM employee".equals(select) ? "测试成功" : "测试失败");
	}

	static String buildSelectSql(String table, String[] fields) {
		var sj = new StringJoiner(", ", "SELECT ", " FROM " + table);
		for (String field : fields) {
			sj.add(field);
		}
		
		return sj.toString();
	}

}

  • 1

Reply