1.组装要提交的数据
var proArr = new Array();
var product = {};
product.productName = $("#productName").val();
proArr.push(product);
2.通过ajax提交
$.ajax({
url:actionUrl,
data:JSON.stringify({proList:proArr}),
type:"post",
contentType:"application/json;charset=UTF-8",
success:function(){
console.info("success...");
}
}})
3.后台接收
@RequestMapping(value = "/save", method = RequestMethod.POST)
public void save(@RequestBody ReceiveModel receiveModel ){
}
public class ReceiveModel {
private List proList; //此处名称需要跟提交的参数名称对应//set,get方法
}
public class Product {
private String productName ;//此处名称需要跟js数组中元素属性值保持一致//set,get方法
}
var proArr = new Array();
var product = {};
product.productName = $("#productName").val();
proArr.push(product);
2.通过ajax提交
$.ajax({
url:actionUrl,
data:JSON.stringify({proList:proArr}),
type:"post",
contentType:"application/json;charset=UTF-8",
success:function(){
console.info("success...");
}
}})
3.后台接收
@RequestMapping(value = "/save", method = RequestMethod.POST)
public void save(@RequestBody ReceiveModel receiveModel ){
}
public class ReceiveModel {
private List proList; //此处名称需要跟提交的参数名称对应//set,get方法
}
public class Product {
private String productName ;//此处名称需要跟js数组中元素属性值保持一致//set,get方法
}