SpringMvc 檔案上傳注意事項

rgqancy發表於2016-12-20

前端

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, 這樣使用者上傳的空檔案,就沒法儲存了。

相關文章