1:前端调用接口地址 this.
h
t
t
p
.
g
e
t
(
′
/
a
p
i
/
u
s
e
r
/
d
e
t
a
i
l
′
,
p
a
r
a
m
s
:
i
d
)
后
端
接
收
到
的
请
求
就
是
h
t
t
p
:
/
/
l
o
c
a
l
h
o
s
t
:
8080
/
a
p
i
/
u
s
e
r
/
d
e
t
a
i
l
?
i
d
=
1
@
G
e
t
M
a
p
p
i
n
g
(
v
a
l
u
e
=
"
/
d
e
t
a
i
l
"
)
p
u
b
l
i
c
R
e
s
p
<
O
b
j
e
c
t
>
d
e
t
a
i
l
(
@
R
e
q
u
e
s
t
P
a
r
a
m
L
o
n
g
i
d
)
r
e
t
u
r
n
R
e
s
p
.
s
u
c
c
e
s
s
(
m
y
U
s
e
r
S
e
r
v
i
c
e
.
d
e
t
a
i
l
(
i
d
)
)
;
2
:
c
o
n
s
t
i
d
=
1
前
端
调
用
接
口
地
址
t
h
i
s
.
http.get('/api/user/detail', {params:{id}}) 后端接收到的请求就是http://localhost:8080/api/user/detail?id=1 @GetMapping(value = "/detail") public Resp<Object> detail(@RequestParam Long id) { return Resp.success(myUserService.detail(id)); } 2:const id = 1 前端调用接口地址 this.
http.get(′/api/user/detail′,params:id)后端接收到的请求就是http://localhost:8080/api/user/detail?id=1@GetMapping(value="/detail")publicResp<Object>detail(@RequestParamLongid)returnResp.success(myUserService.detail(id));2:constid=1前端调用接口地址this.http.get(’/api/user/detail/’ + id)
后端接收到的请求就是http://localhost:8080/api/user/detail/1
@GetMapping(value = “/detail1/{id}”)
public Resp detail1(@PathVariable(“id”) Long id) {
return Resp.success(myUserService.detail(id));
}
如果存在多个参数,前端就继续在url里拼接参数值,注意:每个参数值前面要有"/"
后端会根据"/"按顺序来截取url里的值,并指定参数名称,
const id = 1
const name = ‘麻子’
比如,前端传两个参数并拼接在url里 this.$http.get(’/api/user/detail/’ + id + ‘/’ + name)
后端接收到的请求就是http://localhost:8080/api/user/detail/1/麻子
@GetMapping(value = “/detail1/{id}/{name}”)
public Resp detail1(@PathVariable(“id”) Long id, @PathVariable(“name”) String name) {
return Resp.success(myUserService.detail(id, name));
}
post方式与上面所说的get的方式一致
如果传递的是参数对象,前端调用接口地址 this.$http.get(’/api/user/detail’, 参数对象),需要转成json格式,
后端用@Requstbody接收即可