1、js文件
function uplodad( $('#fromNameId').form({ url:'controllerurl', onSubmit: function(){ //uploda before something }, success:function(data){ //upload after something },error:function(date){ $.messager.alert(data.errormsg); } }); $('#fromNameId').submit(); );
2、jsp文件
<form id="rundApplyFrom" method="post" enctype="multipart/form-data"> <tr id="trIdCard"> <td>msg:</td> <td><input class="easyui-filebox" id="uploadId" name="sourceFile" style="width:200px"></td> </tr> </from>
3、spring.xml配置文件
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="UTF-8"/> </bean>
4、pojo文件
public class AReFundApplyProcess implements Serializable {
private String prosn ;
private String applyid;
private byte[] annex ;
private Object content;
private MultipartFile[] sourceFile;
// sourceFile geter, seter }
5、javaservice文件
/** * uplodaApplyFile * 方法描述:文件上传方法; * @param request */ public void uplodaApplyFile( AReFundApplyProcess arProcess, AReFundApply aRefundApply){
MultipartFile[] uploadfile=arProcess.getSourceFile();//这里用于获取前台传入Bean中Byte字段中的流;
InputStream fileIs= null; //因为案例中是多文件上传,所以是数组;
aRefundApply.setOrderno(arProcess.getProsn());
try {
if(uploadfile != null&& uploadfile.length>0){
for (int i = 0; i < uploadfile.length; i++) {
MultipartFile file=uploadfile[i];
fileIs= file.getInputStream();
byte[] b = FileCopyUtils.copyToByteArray(fileIs);
if(b.length>0){
arProcess.setAnnex(b);
aReFundApplyCheckService.insertAReFundApplyProcess(arProcess);
}
}
}
} catch (IOException e) {
log.error("上传文件异常...",e);
}
}
参考,待验证。