我有几个文件上传HTML。
<label for="app_snapshot_image_1">SNAPSHOT_1</label>
<input type="file" name="app_snapshot_image_1" id="app_snapshot_image_1" />
<label for="app_snapshot_image_2">SNAPSHOT_2</label>
<input type="file" name="app_snapshot_image_2" id="app_snapshot_image_2" />
<label for="app_snapshot_image_2">SNAPSHOT_3</label>
<input type="file" name="app_snapshot_image_3" id="app_snapshot_image_3" />这是弹簧控制器处理来自WEB的多部分请求。
@RequestMapping(value="/apps/addOrModify/", method=RequestMethod.POST)
public String testUpload(
@RequestParam(required=false) MultipartFile app_snapshot_image_1,
@RequestParam(required=false) MultipartFile app_snapshot_image_2,
@RequestParam(required=false) MultipartFile app_snapshot_image_3) {
...
}然而,上面的控制器只能处理从app_snapshot_image_1到3的3个文件;但这不是我想要的。我想使用Controller处理无限文件。
希望你能理解我的问题,为我的小英语感到抱歉。
发布于 2012-06-01 02:24:00
您需要创建一个模型类,其中包含一个字段,如下所示。
List<MultipartFile> files = LazyList.decorate(new ArrayList<MultipartFile>(),
FactoryUtils.instantiateFactory(MultipartFile.class));带着它的得分手和策划者。现在,您需要将此模型作为@ModelAttribute传递到jsp中,在jsp中有一个用于文件上载的表单。
在jsp中,您需要为用户创建一个新的输入,以便使用javascript上传一个新文件,并在输入标记的name属性中指定值,如方括号中的files[some int value],指定用户在JSP中添加的文件控件的数量。
当您发布包含多个文件的表单时,您可以在控制器中使用相同的@ModelAttribute字段来获得包含多个文件的列表。
希望这能帮到你。
干杯。
https://stackoverflow.com/questions/10843477
复制相似问题