|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
) D+ g$ X) d2 i% _
U0 w0 W3 L' i0 J% Y3 c" k@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:2 S5 Y4 _. {' Y) d& x+ b
; @/ R& O ^" L/ O9 D@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
1 I$ }9 K' i1 m9 @9 \$ T' h- w. Q
6 q6 J/ ~# i% `- _. a- _9 H
; ?/ l" z" t6 b% X+ r7 s- @ResTController; v9 F7 b- W& V# f4 s
- @RequestMapping("/user")
5 o; Q5 e; F* x# P8 k' U6 r - public class UserRestController {
% K/ w# w+ ]- g! ~5 N& \ - @RequestMapping("/getuser/{id}"): T! X* ]6 i4 O2 J
- //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径7 U1 ?! J& h/ D2 ^5 X) Q$ j+ {
- public String getUser(@PathVariable("id") Long id)
0 H: H* _# [5 F6 P1 x+ p( A - {
( r$ W. t d6 X! e1 O* L; p. H - User user = new User();0 `, _: ?! D: I
- user.setFirstname("Donald");2 i b3 {% L+ n% F5 l
- user.setLastname("Xeong");
7 e4 W" M/ s% I" I5 ~4 d! D, } J - user.setAge(40);
3 C N8 z7 p. F3 Y' v - return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();: o5 W* L; q' |4 F$ J* @, O
- }
( U1 U+ q- M* X8 e
$ G# v5 o4 h+ M& \3 z6 [- @RequestMapping(value = "/getData",method = RequestMethod.GET)
y8 [4 R) k8 ~! Q: ~/ V - public String getData() {' a9 F4 o8 c/ Z$ a% Y, J$ |
- return "requestMethod Get";8 E3 {; Y! B% Q" g$ y
- }
2 D l0 s# M5 K& c& v4 j0 F; {/ P - @RequestMapping(value = "/postData",method = RequestMethod.POST)
# ^" \, v1 {. ?! @. p - public String postData()9 o6 \; F* j8 N
- {4 F# x1 q( K! I/ j& l& [
- return "RequestMethod Post";) Y4 o2 C% `- D9 H3 B8 ~! t4 ~& f
- }
6 \& g/ i; m# T* a5 \8 K/ I- S - }
" }3 }( U( y/ I h r: k# J0 q) h1 N9 C i
) O/ N3 }+ q# _9 }2 [
复制代码 5 U) n8 F: L# L, i5 U- O2 D0 u
! H9 O3 G3 _8 }3 F! D5 w1 _
& \/ E/ G$ m. b; D8 P8 w* t
! S& W. W( l6 Y
|
|