SpringMvc 文件上传注意事项

前端

1.表单提交方法与格式

<form class="form-horizontal" action="/biz/patent/edit" method="post" enctype="multipart/form-data">

2.input注意不要写value=""

<input type="file" name="attorneyFile" />

 

后端

3.package org.springframework.web.multipart;

Entity.java

private MultipartFile attorneyFile;

4.entity.getAttorneyFile() != null不发生,即使你在HTML里没选任何文件, 仍然有实例,类型为DiskFileItem(package org.apache.commons.fileupload.disk)。

entity.getAttorneyFile() != null && !entity.getAttorneyFile() .getOriginalFilename().equals("")

注意:不能用getSize() > 0, 这样用户上传的空文件,就没法保存了。

posted @ 2016-12-20 17:36  任国强  阅读(325)  评论(0编辑  收藏  举报