CodeController { @RequestMapping(value = "/files") public ServiceResult<List<W2uiElement>> getFiles(@RequestParam(value = "projectId", defaultValue = "") String projectId, @RequestParam(value = "name", defaultValue = "") String name) { if (StringUtils.isBlank(projectId) || StringUtils.isBlank(name)) { return ServiceResult.fail("projectId 或 name 为空!!!"); } List<W2uiElement> files = new ArrayList<>(); File currentProjectDir = new File(new File(consts.codeConsoleilePath, projectId), CodeGenConsts.JAVA); if (currentProjectDir.exists()) { File currentFile; if (StringUtils.isBlank(name)) { currentFile = currentProjectDir; } else { currentFile = new File(currentProjectDir, name); } for (File f : currentFile.listFiles()) { W2uiElement element = new W2uiElement(); if (null == name || name.isEmpty()) { element.setId(String.format("%s_%d", projectId, files.size())); } else { element.setId(String.format("%s_%s_%d", projectId, name.replace("\\", ""), files.size())); } if (null == name || name.isEmpty()) { element.setData(f.getName()); } else { element.setData(name + File.separator + f.getName()); } element.setText(f.getName()); element.setChildren(f.isDirectory()); if (element.isChildren()) { element.setType("folder"); } else { element.setType("file"); } files.add(element); } } return ServiceResult.success(files); }  @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);  }
@Test public void getFiles() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/code/files") .contentType(MediaType.APPLICATION_JSON_UTF8) .param("projectId", "1") .param("name", "tom") .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()); }