|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 e' O1 Y7 X6 o
+ o) Y0 @* I9 k* D' Q' P
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式: u$ z0 y( [# \+ c G
! Y" H' S1 [+ Y$ J- x
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
# i9 R8 R+ k& `7 s0 E1 ?9 |& b z5 C. b# L3 W
8 P/ q9 b/ K) e- @ResTController
+ y) s* e" w) V9 a6 Q8 v - @RequestMapping("/user")
" J& V0 _1 R+ s6 N. \ - public class UserRestController {
( J6 Z' E8 U" ~+ w- T - @RequestMapping("/getuser/{id}") z. c! j& q! P3 O0 _) o
- //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径
7 x7 X, X+ E p' f. _4 B# R - public String getUser(@PathVariable("id") Long id)0 ?7 c# M$ j! k. W
- {
1 B( D d2 q: }- B4 h9 x% H; m - User user = new User();5 ]- I$ p+ O% z4 a: m' C
- user.setFirstname("Donald");7 y& J7 j+ h! R# g# I- v# h0 N
- user.setLastname("Xeong");2 {; g7 l. \# w G3 {: r
- user.setAge(40);
; r# }: x6 ~ \- X+ b2 \: _ - return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();1 }9 b7 h5 ^9 Y; R' E! g
- }. z1 C8 I4 V, U
- z8 h, w3 h" y7 Q- @RequestMapping(value = "/getData",method = RequestMethod.GET)
7 \0 w. ]) A7 Q f! \/ z - public String getData() {
7 D' {' t4 h6 s# _ p. b3 E - return "requestMethod Get";
3 A( X6 v1 l1 r - }
! h# z; q3 D- { - @RequestMapping(value = "/postData",method = RequestMethod.POST)
" T& ?$ W l# ` - public String postData()( v q+ {! n. p: Z O0 d
- {9 P& P( \3 E2 Y$ o; g- j
- return "RequestMethod Post";
+ S- a# B0 F) B) i6 h - } A( N0 D4 Y, D: {2 u
- }$ p% E/ V4 \9 [3 c4 T P& A
+ L8 L% t; A+ q5 U1 @/ t
复制代码
+ j$ y$ n3 V; V: e! c Z& s
+ M# R }1 @5 _$ w& c
$ v* E, D+ A- E" _5 _6 w: Z: x# W* W5 y8 w9 t8 \6 L2 n% L
|
|