spring3.0 mvc 文件下载

@RequestMapping(value = "/export" , method = RequestMethod.GET)
public ResponseEntity<byte[]> download(
HttpServletRequest request,
HttpServletResponse response
) throws IOException {

String text = "内容neirong123"; 

Calendar calendar = Calendar.getInstance();


String date = Utils.getStrDateByFormat(calendar.getTime(),"yyyy-MM-dd");

String fileName = date+".xls";

   HttpHeaders headers = new HttpHeaders();  
   headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);  
   headers.setContentDispositionFormData("attachment", new String(fileName.getBytes("gb2312"),"iso8859-1"));
   return new ResponseEntity<byte[]>(text.getBytes(),headers, HttpStatus.CREATED);  
}

你可能感兴趣的:(spring,mvc,String,Stream,calendar,download)