一、post請求傳遞數組參數值
var ids = new Array();
$.ajax({
type:"post",
url:"${request.getContextPath()}/*****",
dataType:"json",
data:{"idList":ids},
traditional:true,
success:function(data){
}
})
注意:traditional:true的使用;ids數組裏是單個的值
後臺接收的方式:
1、可以直接用request獲取,request.getParameterValues('idList');
2、可以使用註解方式獲取(使用springMVC),這種方式直接就可以獲取到參數。
public String test(@RequestParam(value = "idList", required = false) Long[] idList){
...............
}
二、post請求傳遞數組對象
var tts = new Array();
$.ajax({
type:"post",
url:encodeURI("${request.getContextPath()}/*****"),
contentType:"application/json",
dataType:"json",
async:false,
data:JSON.stringify(tts),
success:function(data){}
})
注意:數組裏是對象
後臺springMVC直接用List<Map>接收
public String test(@RequestBody List<Map<String,String>> map){}
三、post請求傳遞數組及其他參數
$.ajax({
type : "post",
url : encodeURI("${request.getContextPath()}/*****"),
data{"idList":ids,"t1":t1,"t2":t2,"t3":t3},
dataType:"json",
traditional:true,
success : function(data) {
});
後臺springMVC接收:
public String test(@RequestParam(value = "idList", required = true) Long[] idList,
@RequestParam(value = "t1", required = true) String t1,
@RequestParam(value = "t2", required = true) String t2,
@RequestParam(value = "t3", required = true) String t3) {}