【发布时间】:2016-02-22 15:53:14
【问题描述】:
我想将上传的详细信息显示到列表中,我更喜欢使用任何简单的步骤来显示所有详细信息。以下是我每次上传文件时只能显示一个数据的代码。我也明白我应该在 get 方法中创建“addObject”,而不是 post 方法。如何以 arrayList 或任何其他方式显示?任何帮助将不胜感激!
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>
【问题讨论】:
-
您想在
fileList中显示每个Session上传的所有文件??
标签: java html spring-mvc