meterSphere通过for循环构建请求参数
beanshell脚本
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
List list = new ArrayList();
list.add("11551860610584576");
list.add("11551860610584577");
list.add("11551860610584578");
list.add("11551860610584579");
list.add("11551860610584580");
list.add("11551860610584581");
//putObject()可以在vars对象中放置Object类型对象
vars.putObject("list",list);
//===========================
//获取Object list对象
Object Value = vars.getObject("list");
//log.info只能输出String类型变量
log.info("测试:"+Value.toString());
List listNew = new ArrayList();
for (int i=0; i<list.size();i++){
log.info("id:"+list.get(i));
String newId=list.get(i);
String testStr="{\"materialId\":null,\"id\":\"oldId\",\"materialCode\":\"WL-0508-123\",\"materialName\":\"测试物料\",\"materialUnit\":\"套\",\"isEnabled\":1,\"createdBy\":\"System\",\"createdOn\":\"2023-05-08T20:11:53\",\"updatedBy\":\"23099\",\"updatedOn\":\"2023-05-09T09:20:20\"}";
test = testStr.replaceAll("oldId", newId);
log.info(test);
listNew.add(test);
}
log.info("构建后数据:"+listNew.toString());
vars.put(${__metersphere_env_id}+"receiptNoticeDetail",listNew.toString());
vars.put("receiptNoticeDetail",listNew.toString());
log.info("receiptNoticeDetail: "+vars.get("receiptNoticeDetail"));