나는의 값을 얻으려고 keyset()
의를 hashmap
하고 엑셀 시트에 사람들을 인쇄 할 수 있습니다. 그리고 이것은 내 hashmap
모습입니다.
public Map<String, CodaReportDTO> dateAndDTO = new HashMap<>(); //hashmap for date and the dto
따라서 위의 CodaReportDTO
경우 특정 날짜에 대한 요소가 포함되어 있습니다. 그래서 hashmap keyset
날짜를 먼저 인쇄하기 위해 다음 과 같이 반복했습니다 .
for (String dateKey : dateAndDTO.keySet()) { //dateAndDTO is the object
Row tableDataRow = sheet.createRow(tableDataRowCount);
Cell cell = tableDataRow.createCell(1);
cell.setCellValue(dateKey);
}
따라서 반복하고 키 값 (즉, 날짜 값)을 가져 오려면 a List
또는 a 여야합니다 Map
. 클래스 hashmap
가 포함 된에 대해 어떻게 할 수 DTO
있습니까?
나는 이와 같은 일을해야하지만 클래스를 다음과 같이 캐스팅 할 수 없습니다 List
.
List<Map<String, String>> tableCellData = (List<Map<String, String>>) dateAndDTO.get(dateKey);
for (Map<String, String> singleCellTableData : tableCellData) {
int dateCellRef = dateCellReferences.get(singleCellTableData.keySet().iterator().next());
Cell tableCell = tableDataRow.createCell(dateCellRef);
tableCell.setCellValue(Integer.parseInt(singleCellTableData.values().iterator().next()));
}
편집하다
내가 어디로 잘못 가고 있습니까? 어떤 도움을 주시면 감사하겠습니다.
내가 당신의 질문이 맞다면, 당신은 이와 같은 것이 필요합니다
public Map<String, CodaReportDTO> dateAndDTO = new HashMap<>(); //hashmap for date and the dto
Set<Entry<String, CodaReportDTO>> entrySet = dateAndDTO.entrySet();
for(Entry<String, CodaReportDTO> entry : entrySet){
entry.getKey(); //your String key i.e. date in your case
entry.getValue(); //your DTO value for this key
...
}
도움이 되었기를 바랍니다!
행운을 빕니다!
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다