嗨,我正在尝试在特定时间使用 @Scheduled(cron = "0 0/1 * * * *") 自动生成 xls 报告,但它不起作用。请任何人提供想法。谢谢
Hi according to with what you are trying to do, I would use this approach:
So technically would be something like this:
@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
}
In your controller
@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());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.