在前端用axios需要這樣寫
/**
* 刪除數據
*/
export function del(url, data = {}) {
return axios.delete(url, { data: qs.stringify(data) })
}
在瀏覽器中傳輸參數是在Request Payload中的,與以往的formdata不同
后台接收需要額外的方法
后台要想從Request Payload中得到自己想要的數據,就要從流中來獲取數據,具體的代碼為
ong evalutorId = null;
//從Request Payload中獲取數據,從流中來獲取數據
ServletInputStream is;
try {
is = request.getInputStream();
int nRead = 1;
int nTotalRead = 0;
byte[] bytes = new byte[10240];
while (nRead > 0) {
nRead = is.read(bytes, nTotalRead, bytes.length - nTotalRead);
if(nRead > 0)
nTotalRead = nTotalRead + nRead;
}
// str為evalutorId=20
String str = new String(bytes, 0, nTotalRead, "utf-8");
String[] split = str.split("=");
evalutorId = Long.parseLong(split[1]);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
參考:https://blog.csdn.net/Your_heart_private/article/details/71436210