String today=DateUtil.today()
String today = “2024-02-01”;
往前30天
DateTime parseDateUtil.offsetDay(DateUtil.parse(DateUtil.today()), -30)
String today =DateUtil.formatDate(DateUtil.offsetDay(DateUtil.parse(DateUtil.today()), -45));
DateTime parse = DateUtil.parse(DateUtil.today());
String today =DateUtil.formatDate(parse)
postIdMap.computeIfAbsent(dingDaykey.getPostId(), k -> new LinkedList<>()).add(dingDaykey);
优化前
DayEntity dayEntity = lkeyMap.get(line);
if (dayEntity == null) {
dayEntity = new DayEntity();
}
dayEntity.setName(line);
优化后
DayEntity dayEntity = lkeyMap.computeIfAbsent(line, DayEntity::new);
优化前
List<DataListMxfEntity> data = dayEntity.getData();
if (data == null) {
data = new ArrayList<>();
}
优化后
List<DataListMxfEntity> data = Optional.ofNullable(dayEntity.getData()).orElseGet(ArrayList::new);
优化前
List<AgvSg03PsPlcItemHistoryDO> agvSg03PsPlcItemHistoryDOS1 = batteryIdMapList.get(batteryId);
if (agvSg03PsPlcItemHistoryDOS1 == null) {
agvSg03PsPlcItemHistoryDOS1 = new ArrayList<>();
}
优化后
List<AgvSg03PsPlcItemHistoryDO> agvSg03PsPlcItemHistoryDOS1 = Optional.ofNullable(batteryIdMapList.get(batteryId))
.orElseGet(ArrayList::new);
String fileName = "1.json";
String currentFilePath = new Object(){}.getClass().getEnclosingClass().getResource("").getPath()+fileName;
String substring = currentFilePath.replaceAll("target/test-classes", "src/test/java").substring(1);
String jsonPath = substring;
System.out.println("jsonPath = " + jsonPath);
控制台输出:
jsonPath = D:/desktop/xiangmu/doc_translation/src/test/java/com/example/dxw/1.json