アプリケーションのフォルダーエンティティにリンクされているディレクトリ内のファイルのリストがあり、すべてのファイルは一意のフォルダークラスに関連付けられており、フォルダー id ==> folder.id = file.name ファイルエンティティと同じ参照を持っています。フォルダのコンテンツを表示しようとすると、フォルダにリンクされているものだけでなく、すべてのディレクトリ ファイルが取得されます。彼女は私のサービスでフォルダのコンテンツを表示します
@RequestMapping("/displayfolder")
public String displayfolder(Model model, String reffolder, String filename,
@RequestParam(name="page", defaultValue="0") int page,
@RequestParam(name="size", defaultValue="10") int size){
model.addAttribute("reffolder", reffolder);
model.addAttribute("filename", filename);
try{
Folder folder = folderprocess.displayfolder(reffolder);
model.addAttribute("folder", folder);
model.addAttribute("files", storageService.loadAll().map(
path -> ServletUriComponentsBuilder.fromCurrentContextPath()
.path("/Files/")
.path(path.getFileName().toString())
.toUriString())
.collect(Collectors.toList()));
}catch (Exception e) {
model.addAttribute("error", e);
return "redirect:/displayfolder?reffolder="+reffolder+
"&error="+e.getMessage();
}
return "edit_folder";
}
loadAll() サービス:
public Stream<Path> loadAll() {
try {
return Files.walk(this.rootLocation, 1)
.filter(path -> !path.equals(this.rootLocation))
.map(this.rootLocation::relativize);
}
catch (IOException e) {
throw new StorageException("Failed to read stored files", e);
}
}
要求されたフォルダーにリンクされているファイルのみを取得するにはどうすればよいですか? ありがとう