List截取指定长度(java截取拼接URL)

2023-12-13 03:30:05

?场景:

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;
            //拆LIST
            final List<Integer> sonList = memberNos.subList(start, end);

            //拼接url
            final String url = "http://xxxxxx?" + sonList.stream().map(item -> item.toString()).collect(Collectors.joining(","));
            //组装后的url
            System.out.println(url);
            count++;
        }
    }

linux shell脚本:

#!/bin/bash
# 文件名
input file=$1
# 拼接的url前缀
url="http://xxxx'
# 读取一行
while IFS= read -r line
do
	arr=($line)
	memberList=s{arr[0]]
	echo "para: $line" >> $input file.output
	# post请求,参数名memberList
	result=$(curl -d "[\"memberList ": [$memberlist]]" -H "Content-Type: application/json" -X POST "$url")
	# 响应结果输出文件
	echo "Result: $result" >> $input_file.output
	echo "-----" >> $input_file.output
	sleep 2

done < "$input_file"

文章来源:https://blog.csdn.net/hgg923/article/details/134879783
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。