json 格式:
{type:1, appKey: "aaa", sign: "bbb"}
后台代码:
<span style="white-space:pre"> </span>@RequestMapping(value="/getEventList", method=RequestMethod.POST)
@ResponseBody
public Object getEventList(@RequestBody Map<String, Object> map){
logger.info("test");
logger.info(map.get("type"));
Map<String, Object> json = new HashMap<String, Object>();
json.put("code", "200");
return json;
}
前台代码:
function dojson(){
$.ajax({
type: "post",
dataType:"json",
contentType: "application/json;charset=utf-8",
url: "<%=basePath%>getEventList",
data: JSON.stringify({type:1, appKey: "aaa", sign: "bbb"}),
success: function (result) {
}
});
}
json 格式:
{type:1, productList:[{productId:1,stock:1},{productId:2,stock:2}]}
后台代码:
<span> </span>@RequestMapping(value="/getEventList", method=RequestMethod.POST)
@ResponseBody
public Object getEventList(@RequestBody Map<String, Object> map){
logger.info("test");
logger.info(map.get("type"));
List<LinkedHashMap<String, Object>> lista = (List<LinkedHashMap<String, Object>>) map.get("productList");
System.out.println(lista.get(0).get("productId"));
System.out.println(lista.get(0).get("stock"));
Map<String, Object> json = new HashMap<String, Object>();
json.put("code", "200");
return json;
}
前台代码:
function dojson(){
$.ajax({
type: "post",
dataType:"json",
contentType: "application/json;charset=utf-8",
<span style="white-space:pre"> </span>url: "<%=basePath%>getEventList",
data: JSON.stringify({type:1, productList:[{productId:1,stock:1},{productId:2,stock:2}]}),
success: function (result) {
}
});
}