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

场景:

N多个参数,截取指定个数,拼接URL

java 复制代码
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脚本:

bash 复制代码
#!/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"
相关推荐
cici1587412 分钟前
C#实现三菱PLC通信
java·网络·c#
k***92161 小时前
【C++】继承和多态扩展学习
java·c++·学习
weixin_440730501 小时前
java结构语句学习
java·开发语言·学习
JIngJaneIL1 小时前
基于java+ vue医院管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
Coder_Boy_1 小时前
Spring AI 源码大白话解析
java·人工智能·spring
仙俊红2 小时前
在 Java 中,`==` 和 `equals()` 的区别
java·开发语言·jvm
计算机学姐2 小时前
基于SpringBoot的高校论坛系统【2026最新】
java·vue.js·spring boot·后端·spring·java-ee·tomcat
予枫的编程笔记2 小时前
Redis 核心数据结构深度解密:从基础命令到源码架构
java·数据结构·数据库·redis·缓存·架构
JIngJaneIL2 小时前
基于java + vue校园跑腿便利平台系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
飞舞花下2 小时前
MAVEN私有仓库配置-Nexus私有仓库
xml·java·maven