gpt4 book ai didi

java - 我如何过滤这个映射以生成更优雅和干净的sql更新?

转载 作者:行者123 更新时间:2023-12-01 19:32:07 25 4
gpt4 key购买 nike

我有这张 map :

Map<String, String> strMap = new HashMap<>();

我把这个放在他身上:

strMap.put("A1565ZMM", "35;9109890019;35;127;A1565ZMM;01280651687;12458754;3;15439443");
strMap.put("A1558IE8", "35;9109890019;35;127;A1558IE8;01280651687;11034003;3;15439443");
strMap.put("A1565ZN2", "35;9109890019;38;127;A1565ZN2;01280651687;12458761;3;15439520");
strMap.put("A1558IID", "35;9109890019;38;127;A1558IID;01280651687;11034143;3;15439520");
strMap.put("A1567OR5", "35;9109890019;39;127;A1567OR5;01280651687;12534143;3;15532787");
strMap.put("A1558IQ2", "35;9109890019;39;127;A1558IQ2;01280651687;11034367;3;15532787");
strMap.put("A155YM40", "35;9109890019;40;127;A155YM40;01280651687;12201754;3;14210415");
strMap.put("A1558IOA", "35;9109890019;40;127;A1558IOA;01280651687;11034318;3;14210415");
strMap.put("A1565ZNE", "35;9109890027;3 ;127;A1565ZNE;01001671600;12458774;3;15436154");
strMap.put("A1558J1J", "35;9109890027;3 ;127;A1558J1J;01001671600;11034759;3;15436154");

这是我想写得更好的代码,但我不知道如何写如何才能写出更优雅的代码?

List<String> tuple = mapaResgatesSQL.values().stream().map(u -> 
new StringBuilder("UPDATE <TABLE> SET STATUS = 12 WHERE ID = ")
.append(u.split(";")[3])
.append(" AND IDAAA = ")
.append(u.split(";")[6])
.append(" AND IDBBB = '")
.append(u.split(";")[5])
.append("' AND CODCCC = ")
.append(u.split(";")[4])
.append(" AND IDDDD = ")
.append(u.split(";")[1])
.append(" AND NUMEEE = ")
.append(u.split(";")[2])
.append(";")
.toString()
).collect(Collectors.toList());

tuple.add("COMMIT;");

最佳答案

您可以使用以下格式更简洁:

public static final String QUERY = "UPDATE <TABLE> SET STATUS = 12 WHERE ID = %s AND IDAAA = %s AND IDBBB = '%s' AND CODCCC = %s AND IDDDD = %s AND NUMEEE = %s";

并进一步分割一次:

List<String> tuple = mapaResgatesSQL.values().stream()
.map(s -> s.split(";"))
.map(splits -> String.format(QUERY, splits[3], splits[6], splits[5], splits[4], splits[1], splits[2]))
.collect(Collectors.toList());

关于java - 我如何过滤这个映射以生成更优雅和干净的sql更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59396951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com