对象有31个日字段,根据map的key自动对应的日字段,并把value赋值到对象的日字段里

2023-12-14 20:32:09

正文

我希望对象有个属性,分别是:private String day1;
private String day2;
private String day3;
现在有一个map,当key=1,seyDay1(map.get(1)),当key=2,seyDay2(map.get(2)),当key=3,seyDay3(map.get(3))。

实体类

private String day1;
	private String day2;
	private String day3;
	private String day4;
	private String day5;
	private String day6;
	private String day7;
	private String day8;
	private String day9;

代码

List<ScheduleDateDetailVO> details = record.getDetails();
			ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
			Map<String, BiConsumer<CheckSummaryReport, String>> setterMap = new HashMap<>();
			setterMap.put("1", CheckSummaryReport::setDay1);
			setterMap.put("2", CheckSummaryReport::setDay2);
			setterMap.put("3", CheckSummaryReport::setDay3);
			setterMap.put("4", CheckSummaryReport::setDay4);
			setterMap.put("5", CheckSummaryReport::setDay5);
			setterMap.put("6", CheckSummaryReport::setDay6);
			setterMap.put("7", CheckSummaryReport::setDay7);
			setterMap.put("8", CheckSummaryReport::setDay8);
			setterMap.put("9", CheckSummaryReport::setDay9);
			setterMap.put("10", CheckSummaryReport::setDay10);
			setterMap.put("11", CheckSummaryReport::setDay11);
			setterMap.put("12", CheckSummaryReport::setDay12);
			setterMap.put("13", CheckSummaryReport::setDay13);
			setterMap.put("14", CheckSummaryReport::setDay14);
			setterMap.put("15", CheckSummaryReport::setDay15);
			setterMap.put("16", CheckSummaryReport::setDay16);
			setterMap.put("17", CheckSummaryReport::setDay17);
			setterMap.put("18", CheckSummaryReport::setDay18);
			setterMap.put("19", CheckSummaryReport::setDay19);
			setterMap.put("20", CheckSummaryReport::setDay20);
			setterMap.put("21", CheckSummaryReport::setDay21);
			setterMap.put("22", CheckSummaryReport::setDay22);
			setterMap.put("23", CheckSummaryReport::setDay23);
			setterMap.put("24", CheckSummaryReport::setDay24);
			setterMap.put("25", CheckSummaryReport::setDay25);
			setterMap.put("26", CheckSummaryReport::setDay26);
			setterMap.put("27", CheckSummaryReport::setDay27);
			setterMap.put("28", CheckSummaryReport::setDay28);
			setterMap.put("29", CheckSummaryReport::setDay29);
			setterMap.put("30", CheckSummaryReport::setDay30);
			setterMap.put("31", CheckSummaryReport::setDay31);
			for (ScheduleDateDetailVO detail : details) {
				LocalDate checkDate = detail.getCheckDate();
				int day = checkDate.getDayOfMonth();
				String key = day + "";
				map.put(key, detail.getCheckDesc());
			}
			map.forEach((k, v) -> {
				setterMap.get(k).accept(checkSummaryReport, v);
			});
			checkSummaryReportList.add(checkSummaryReport);

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