『 파일 다운로드(ResponseEntity사용)

​<소스코드>

​@Controller
public class DownloadController {
   
    // ResponseEntity를 사용하는 경우
    @RequestMapping(value="/downloadFile2", method = {RequestMethod.GET} )
    public ResponseEntity<String> downloadFile2() throws IOException {
       
        // HTTP헤더 지정
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(new MediaType("application", "octet-stream"));
        headers.set("Content-Disposition", String.format("filename=\"%s\"", "sample.txt"));
       
        String data = "HelloWorld!";
        return new ResponseEntity<String>(data, headers, HttpStatus.OK);
       
    }
}



 

 

 


 

 

+ Recent posts