ajax 请求方式
1.如果后台接收参数中使用
@RequestBody
那么
$.ajax({
url:CONTEXT_PATH+"/lotPlatform/getLastState",
type: "post",
contentType:'application/json',
dataType: "json",
traditional:true,
data:JSON.stringify({'deviceName':'hangtian2'}),
success:function(data){
console.log(data);
}
})
2、如果没有
$.ajax({
url:CONTEXT_PATH+"/lotPlatform/getLastState",
type: "post",
contentType: "application/x-www-form-urlencoded",
dataType: "json",
traditional:true,
data:{deviceName:'hangtian2'},
success:function(data){
console.log(data);
}
})
Post:
x-www-form-urlencoded 接收是 User user,不用添加@RequestBody
application/json + 字符串 接收是 @RequestBody User user
application/json + from-data 接收是 User user ,不用添加@RequestBody。可以用于文件的上传传输
Get:
如果是参数:
可以直接用 String name
或者RequestParam(name="name") String name
如果在url中的参数:
使用@PathVariable("id") Long id

浙公网安备 33010602011771号