对象反射到map转换
把参数从shell读取出来后,放到全局map中
import java.io.File;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.beanutils.BeanUtils;
import com.github.crab2died.ExcelUtils;
public class Apitest {
public static void main(String[] args) throws Exception {
HttpClientUtils.openProxy=true;
String excelPath=System.getProperty("user.dir")+File.separator+"data"+File.separator+"apitest6.xlsx";
Map<String, Object> map=new HashMap<String, Object>();
map.put("id", "id001");
List<ParamsBean> listParams=ExcelUtils.getInstance().readExcel2Objects(excelPath, ParamsBean.class,1);
for (ParamsBean paramsBean : listParams) {
Field[] fields=paramsBean.getClass().getDeclaredFields();
for (Field field : fields) {
System.out.println(field.getName()+" "+BeanUtils.getProperty(paramsBean, field.getName()));
map.put(field.getName(), BeanUtils.getProperty(paramsBean, field.getName()).toString());
}
}
}
}
整合apitest导致下图问题
解决上述问题
参数化统一处理
import java.io.File;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import com.github.crab2died.ExcelUtils;
public class Apitest {
static String regex="\\$\\{(.+?)\\}";
static Pattern pattern=Pattern.compile(regex);
static Map<String, Object> map=new HashMap<String, Object>();
public static void main(String[] args) throws Exception {
HttpClientUtils.openProxy=true;
String excelPath=System.getProperty("user.dir")+File.separator+"data"+File.separator+"apitest6-2.xlsx";
// List<TestCase> listTestcase=ExcelUtils.getInstance().readExcel2Objects(excelPath, TestCase.class);
map.put("id", "id001");
List<ParamsBean> listParams=ExcelUtils.getInstance().readExcel2Objects(excelPath, ParamsBean.class,1);
for (ParamsBean paramsBean : listParams) {
// System.out.println(paramsBean);
Field[] fields=paramsBean.getClass().getDeclaredFields(