1.数据类型
scgedulings:[
ScgedulingVO{
v_day1='1825427303686995970',
v_day2='1825427303686995970',
......
}
]
2.代码块
//定义常量
private static Map<String,Method> itemSwitchMap;
//静态代码块
static{
itemSwitchMap = new HashMap<>();
//获取对象的方法数组
Method[] methods = ScgedulingVO.class.getMethods();
//遍历数组
for(Method method : methods){
String methodName = method.getName();
//包含**跳出
if(methodName.indexOf("set") >= 0 || methodName.indexOf("wait") >= 0){
continue;
}
methodName = methodName.substring(5).toLowerCase();
itemSwitchMap.put(methodName,method);
}
}
3.获取代码
//通过名称获取对应的值
String date = "2024-05-07";
String day = date.substring(8,10);
int dayNum = Integer.parseInt(day);
String newDay = "day" + dayNum;
try{
Sting id = (String) itemSwitchMap.get(newDay).invoke(scgedulings.get(j));
}catch(IllegalAccessException e){
e.printStackTrace();
}catch(InvocationTargetException e){
e.printStackTrace();
}