轉載: https://blog.csdn.net/qq_37164847/article/details/88885917
后台接收參數:
// 刪除用戶
@PostMapping("/del")
public AppResult<String> del(@Param("userId")long userId){
log.info("刪除用戶");
log.info("刪除用戶userId:"+userId);
return AppResultBuilder.success("刪除成功", ResultCode.SUCCESS);
}
原始前端傳遞參數:
$.ajax({
headers: {
"Authorization":token//此處放置請求到的用戶token
},
url:posturl,
type: "post",
data:{"userId":22},
contentType: "application/json",
dataType: 'json',
async: true,
success: function(res) {
console.log("提交結果=="+JSON.stringify(res));
},
error:function() {
console.log("提交失敗");
}
});
后端接收顯示是null,解決:
把 contentType: "application/json",
dataType: 'json',
去掉