场景:
N多个参数,截取指定个数,拼接URL
public static void main(final String[] args) {int count = 0;//每页数量final int pageSize = 5;final List<Integer> memberNos = ListUtil.toList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);while (true) {final int start = count * pageSize;if (start >= memberNos.size()) {break;}final int end = (count + 1) * pageSize > memberNos.size() ? memberNos.size() : (count + 1) * pageSize;//拆LISTfinal List<Integer> sonList = memberNos.subList(start, end);//拼接urlfinal String url = "http://xxxxxx?" + sonList.stream().map(item -> item.toString()).collect(Collectors.joining(","));//组装后的urlSystem.out.println(url);count++;}}
linux shell脚本:
#!/bin/bash
# 文件名
input file=$1
# 拼接的url前缀
url="http://xxxx'
# 读取一行
while IFS= read -r line
doarr=($line)memberList=s{arr[0]]echo "para: $line" >> $input file.output# post请求,参数名memberListresult=$(curl -d "[\"memberList ": [$memberlist]]" -H "Content-Type: application/json" -X POST "$url")# 响应结果输出文件echo "Result: $result" >> $input_file.outputecho "-----" >> $input_file.outputsleep 2done < "$input_file"