This is my html file. I did a list with all my file from DB.
File Name:
<input list="files" name="files" />
<datalist id="files">
<option th:each="file: ${files}" th:value=" ${file.fileName}"></option>
</datalist>
<button type="submit">OK</button>
</form>
</div>
When I select a file I want to know what file I select. This is the controller. The File from post method is always empty...
@Autowired
public FileRepository fileRepository;
@GetMapping("/getFiles")
public String fileGet(Model model) {
List<File> files = new ArrayList<>();
files = fileRepository.findAll();
model.addAttribute("files", files);
model.addAttribute("file", new File());
return "filesFromDB";
}
@PostMapping("/getFiles")
public String filePost(@ModelAttribute("file") File file, Model model) {
model.addAttribute("fileName", file.getFileName());
System.out.println("File: " + file.getFileName());
return "resultFileDB";
}
Aucun commentaire:
Enregistrer un commentaire