[英]How to using @Scheduled(cron = "0 0/1 * * * *") automatically Generate xls report in Spring MVC
嗨,我正在嘗試在特定時間使用 @Scheduled(cron = "0 0/1 * * * *") 自動生成 xls 報告,但它不起作用。請任何人提供想法。謝謝
嗨,根據您的嘗試,我會使用這種方法:
所以從技術上講是這樣的:
@Scheduled(cron = "0 0/1 * * * *")
public void freezeDateTwo(){
System.out.println("shudler Working");
service.updateFreezeOnDateTwoAndSixteen();
List<ExtusrRole> user = service.getExtUser();
excelReport(user);
//In this point you should have created a report in some specific location
}
在您的控制器中
@RequestMapping(value = "/reports/{dd}/{mm}/{yyyy}", method = RequestMethod.GET)
@ResponseBody
private void excelReport(@PathVariable("dd") Integer day,
@PathVariable("mm") Integer month,
@PathVariable("yyyy") Integer year,
HttpServletResponse response) {
System.out.println("excelReport");
//Search from your specific location the right report
File file = //Your file
String mimeType = URLConnection.guessContentTypeFromName(file.getName());
response.setContentType(mimeType);
response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", file.getName()));
response.setContentLength((int) file.length());
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
FileCopyUtils.copy(inputStream, response.getOutputStream());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.