// 这里BBB是@RequestParam 的ajax
function funcBBB(){
console.log("request...");
$.ajax({
url:"/api/xxx/bbb",
type:"POST",
dataType:"json",
async:false,
data:{
"id":"id001",
"name":"name001"
},
success:function(data){
if("200"==data.code)
{
alert(data.data);
}else{
alert(data.code);
}
},
});
//ccc是@RequestBody的用发
function funcCCC(){
console.log("request...");
$.ajax({
url:"/api/xxx/aaa",
type:"POST",
dataType:"json",
async:false,
contentType:"application/json;charset=utf-8",
data: JSON.stringify({"id":"id0003","name":"name0003"}),
success:function(message){
if("200"==message.code)
{
alert(message.data);
}else{
alert(message.code);
}
},
error:function(message){
$("request-process-patent").html("fail to post");
}
});
@RequestMapping(value="/aaa",method= RequestMethod.POST)
public JsonResult userMgr(@RequestBody Map<String,String> map){
String id=map.get("id");
String name=map.get("name");
}
@RequestMapping(value="/bbb",method= RequestMethod.POST)
public JsonResult usrAdmin(@RequestParam String id, @RequestParam String name){
logger.info("assetIssue parameters:"+ id+":"+name);
}
总结:
RequestParam ajax格式就是{“id”:“5”,name:“huazai”} 这样
而RequestBody ajax 需要 JSON.stringify 转字符串并且加contentType:“application/json;charset=utf-8”,