[英]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.