@Test public void download() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/code/download") .contentType(MediaType.APPLICATION_JSON_UTF8) .param("projectId", "1") .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()); }
@RequestMapping("/download") public String download(@RequestParam(value = "projectId") Long projectId, HttpServletResponse response) throws Exception { File file = new File(new File(consts.codeConsoleilePath, String.valueOf(projectId)), CodeGenConsts.JAVA); Project project = projectDao.getProjectByID(projectId); String date = DateUtil.getCurrentTime(); final String zipFileName = project.getName() + "-" + date + ".zip"; return FileUtils.download(response, file, zipFileName, consts.codeConsoleilePath); }
CodeController { @RequestMapping("/download") public String download(@RequestParam(value = "projectId") Long projectId, HttpServletResponse response) throws Exception { File file = new File(new File(consts.codeConsoleilePath, String.valueOf(projectId)), CodeGenConsts.JAVA); Project project = projectDao.getProjectByID(projectId); String date = DateUtil.getCurrentTime(); final String zipFileName = project.getName() + "-" + date + ".zip"; return FileUtils.download(response, file, zipFileName, consts.codeConsoleilePath); } }
CodeController { @RequestMapping("/download") public String download(@RequestParam(value = "projectId") Long projectId, HttpServletResponse response) throws Exception { File file = new File(new File(consts.codeConsoleilePath, String.valueOf(projectId)), CodeGenConsts.JAVA); Project project = projectDao.getProjectByID(projectId); String date = DateUtil.getCurrentTime(); final String zipFileName = project.getName() + "-" + date + ".zip"; return FileUtils.download(response, file, zipFileName, consts.codeConsoleilePath); }  }
CodeController { @RequestMapping("/download") public String download(@RequestParam(value = "projectId") Long projectId, HttpServletResponse response) throws Exception { File file = new File(new File(consts.codeConsoleilePath, String.valueOf(projectId)), CodeGenConsts.JAVA); Project project = projectDao.getProjectByID(projectId); String date = DateUtil.getCurrentTime(); final String zipFileName = project.getName() + "-" + date + ".zip"; return FileUtils.download(response, file, zipFileName, consts.codeConsoleilePath); }  @RequestMapping(value = "/count") ServiceResult countProject(@RequestParam(value = "projectId", defaultValue = "0") Long projectId); @RequestMapping(value = "/generate", method = RequestMethod.POST) ServiceResult generateProject(@RequestBody GenerateCodeModel generateCodeRequest, HttpServletRequest request); @RequestMapping(value = "/files") ServiceResult<List<W2uiElement>> getFiles(@RequestParam(value = "projectId", defaultValue = "") String projectId,
                                                     @RequestParam(value = "name", defaultValue = "") String name); @RequestMapping(value = "/content") ServiceResult<String> getFileContent(@RequestParam(value = "projectId", defaultValue = "") String projectId,
                                                @RequestParam(value = "name", defaultValue = "") String name); @RequestMapping("/download") String download(@RequestParam(value = "projectId") Long projectId, HttpServletResponse response); @RequestMapping(value = "/clearFiles") ServiceResult clearFiles(@RequestParam(value = "projectId") Integer projectId); }
CodeController { @RequestMapping("/download") public String download(@RequestParam(value = "projectId") Long projectId, HttpServletResponse response) throws Exception { File file = new File(new File(consts.codeConsoleilePath, String.valueOf(projectId)), CodeGenConsts.JAVA); Project project = projectDao.getProjectByID(projectId); String date = DateUtil.getCurrentTime(); final String zipFileName = project.getName() + "-" + date + ".zip"; return FileUtils.download(response, file, zipFileName, consts.codeConsoleilePath); }  @RequestMapping(value = "/count") ServiceResult countProject(@RequestParam(value = "projectId", defaultValue = "0") Long projectId); @RequestMapping(value = "/generate", method = RequestMethod.POST) ServiceResult generateProject(@RequestBody GenerateCodeModel generateCodeRequest, HttpServletRequest request); @RequestMapping(value = "/files") ServiceResult<List<W2uiElement>> getFiles(@RequestParam(value = "projectId", defaultValue = "") String projectId,
                                                     @RequestParam(value = "name", defaultValue = "") String name); @RequestMapping(value = "/content") ServiceResult<String> getFileContent(@RequestParam(value = "projectId", defaultValue = "") String projectId,
                                                @RequestParam(value = "name", defaultValue = "") String name); @RequestMapping("/download") String download(@RequestParam(value = "projectId") Long projectId, HttpServletResponse response); @RequestMapping(value = "/clearFiles") ServiceResult clearFiles(@RequestParam(value = "projectId") Integer projectId);  }