繁体   English   中英

如何使用@Scheduled(cron = "0 0/1 * * * *") 在Spring MVC中自动生成xls报告

[英]How to using @Scheduled(cron = "0 0/1 * * * *") automatically Generate xls report in Spring MVC

嗨,我正在尝试在特定时间使用 @Scheduled(cron = "0 0/1 * * * *") 自动生成 xls 报告,但它不起作用。请任何人提供想法。谢谢

嗨,根据您的尝试,我会使用这种方法:

  1. 每天使用cron生成一个报告文件,存放在某个特定的位置
  2. 创建一个 URL 以通过 dd/MM/yyyy 阅读任何报告

所以从技术上讲是这样的:

@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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM