1. get
//后台用@RequestParam接收,注意传数组时要指明value
export function getA(query) {
return request({
url: '/info',
method: 'get',
params: query
})
}
//后台用@PathVariable接收
export function getB(id) {
return request({
url: '/info/' + id,
method: 'get'
})
}
2. post
//后台用@RequestBody接收data
export function postA(data) {
return request({
url: '/system/user',
method: 'post',
data: data
})
}
//后台用@RequestParam接收pageNo
export function postA(data) {
return request({
url: '/system/user?pageNo='+pageNo,
method: 'post',
})
}
3. put
//后台用@RequestBody接收
export function putA(data) {
return request({
url: '/info',
method: 'put',
data: data
})
}
4. delete
//后台用@PathVariable接收
export function delA(id) {
return request({
url: '/info/' + id,
method: 'delete'
})
}
区别:
-
post和put,都可以完成数据的上行和下行。
post最大的特点是新增,post三次数据,库中会产生3次数据。
put的特点是,同一条数据put3次,库中会产生1次数据,后发的同一条数据的请求会覆盖掉前面的请求。 -
get所带的url是明参,直接在url里带过去。
post参数可以放在body中,也可以放请求头里面。