반응형
CSV 생성 후 다운로드 하기
@RequestMapping("/csvDownload")
public ResponseEntity<String> getTotalList() {
//CSV는 UTF-8로 하면 깨지고, MS949 로 세팅해야 된다.
//import org.springframework.http.HttpHeaders;
HttpHeaders header = new HttpHeaders();
header.add("Content-Type", "text/csv; charset=MS949");
header.add("Content-Disposition", "attachment; filename=\"" + "total.csv" + "\"");
//내용에 콤마가 있을경우 쌍따움표로 감싼다.
String csvData = "가, "나,1,2,3" , 다, \n 1, 2, 3";
return new ResponseEntity<String>(csvData , header, HttpStatus.CREATED);
}
반응형
'IT' 카테고리의 다른 글
Spring 에서 MyBatis로 DB연결 (0) | 2022.11.14 |
---|---|
webjars 못 불러 올때 처리방법 (0) | 2022.10.27 |
[Spring 강좌] Spring 에서 SAX 이용한 대용량 엑셀 읽기 (0) | 2022.10.23 |
[스프링 강좌] 파일 다운로드 처리 소스 (0) | 2022.10.23 |
쿠키를(cookie) 이용한 아이디 저장 (0) | 2022.10.22 |