5,655
社区成员
发帖
与我相关
我的任务
分享
$("#createButton").click(function(){
$("#newsMultiform").submit();
});
$("#newsMultiform").submit(function(e){
var formURL = "/Server/business/news/create";
var formData = new FormData(this); //form中有一个file控件和一个文本控件
$.ajax({
url: formURL,
type: 'POST',
data: formData,
mimeType:"multipart/form-data",
contentType: false,
cache: false,
processData:false,
success: function(data, textStatus, jqXHR)
{
},
error: function(jqXHR, textStatus, errorThrown)
{
}
});
e.preventDefault(); //Prevent Default action.
//e.unbind(); //unbind. to stop multiple form submit.
});
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="resolveLazily" value="true" />
<property name="maxUploadSize" value="10485760" />
</bean>
@Override
@POST
@Path("business/news/create")
@Produces("application/json")
@Consumes("multipart/form-data")
public int createNews(MultipartFile file,String content){
News newsaa = new News();
return 1;
}