这是因为jfinal中的api说到,在带有文件上传的form表单时,需要先获取fiel,才能获取表单值。那么带有文件上传的表单怎样去上传,并获取值呢?
前端页面
var formData = new FormData($('#editForm')[0]); $.ajax({ url: ctx + "/notice/savePublish", data: formData, type: 'post', async: false, processData: false, contentType: false, success: function (data) { if (data.success) { pointLion.alertMsg("发布成功!", "success", "small", function () { doPjax(ctx + "/notice"); }); }else{ $.niftyNoty({ type : 'danger', message : data, container : 'floating', timer : 5000 }); } } })
editForm为form表单的id
form表单中的文件input直接给name为file就行了
后台controller:
UploadFile file = getFile("file"); Project project = getModel(Project.class);