I would like to display uploaded detail into a list, I preferred to go with any easy step in order to display all the detail. Following is my code that is only able to display one data for each time I uploaded a file. I also understand that I should make the "addObject" in the get method, not post method. How can I display in arrayList or any other way? Any help would be appreciated!
This is controller
@RequestMapping(value = "/product", method = RequestMethod.GET)
public Object uploadProducts(@ModelAttribute UploadCreate uploadCreate,HttpSession session,RedirectAttributes redirectAttributes) {
// redirectAttributes.addFlashAttribute("list",employeeDetail.getName());
// redirectAttributes.addFlashAttribute("name",employeeDetail.getName());;
return "product/upload";
}
@RequestMapping(value = "/product", method = RequestMethod.POST, consumes = "multipart/form-data")
public Object uploadProducts(@RequestParam("file") MultipartFile file) {
try {
UploadCreate uploadCreate = new UploadCreate();
uploadCreate.setName(file.getOriginalFilename());
uploadCreate.setContentType(file.getName());
uploadCreate.setContent(file.getBytes());
uploadCreate.setUploadedDate(new Date());
uploadService.uploadProducts(uploadCreate);
return new ModelAndView("product/upload")
.addObject("error", "Product upload scheduled.")
.addObject("fileList", uploadCreate);
} catch (Exception e) {
return new ModelAndView("product/upload").addObject("error", e.getMessage());
}
}
HTML:
<table id="uploaded-files">
<tr>
<th>File Name</th>
<th>File Size</th>
<th>File Type</th>
<th>Uploaded Date</th>
</tr>
{{#fileList}}
<tr>
<td>{{name}}</td>
<td>{{content}}</td>
<td>{{contentType}}</td>
<td>{{uploadedDate}}</td>
</tr>
{{/fileList}}
</table>
Sessionin thefileList??