|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/ V3 A6 t+ i+ E* {$ _
7 z5 Y6 Q& ?" ^. _: b! J
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:
7 _9 M! ?9 H; j! Z) g( a5 Y6 ^! x: k: y9 h+ C
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
2 j. P+ j# M2 y% A q( I
4 ^+ u! `; k b0 N/ W! Q$ R) {- ; d! t2 L8 l& }
- @ResTController& I6 a: r& Y9 P
- @RequestMapping("/user")! f" |; ~2 p! [/ y8 b0 x$ \% E
- public class UserRestController {& r$ }" \" c# s( ?4 G, S
- @RequestMapping("/getuser/{id}")
7 f6 X3 k) `0 G( p# F - //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径
5 y, v" E" F) P - public String getUser(@PathVariable("id") Long id) S, _9 U5 G6 ^0 C. q( Z7 w
- {: J! C+ t0 A0 f6 N) ^
- User user = new User();) {* |, E# N1 @5 H+ e: a e3 r
- user.setFirstname("Donald");: a7 U) Z. q, m& {. N/ m
- user.setLastname("Xeong");* j8 ^6 V V- ?% H9 S
- user.setAge(40);6 {' y. j# f# p7 Q
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();
' l6 i( g; e l2 S3 R3 S% q - }6 Q8 M6 ?- Q% Z+ g0 }
+ z$ [ F* I! M# q0 t- @RequestMapping(value = "/getData",method = RequestMethod.GET)- H ?8 [( ^: P, W) V4 y( K0 B
- public String getData() {$ v0 Z8 f4 a0 e5 n1 J1 m
- return "requestMethod Get";9 K9 q/ Y# H5 B$ U9 |; B
- }
- C }; L6 ^% h2 {3 W4 R9 }1 u" l" e - @RequestMapping(value = "/postData",method = RequestMethod.POST). ]& p# N2 S& i7 g$ m2 G) @6 _
- public String postData()
1 \& v% Q5 T, ]6 A - { C5 X$ L8 o( p, w. I
- return "RequestMethod Post";
5 k1 R. X3 q( i) j - }& {. Y( Z/ s$ C" I3 o
- }, E* y% M+ y3 D6 |4 V/ ^. V
2 |! o# m- \. b# H
复制代码
$ R2 ]4 k. E; i; r, f( }8 u
1 _$ B, H$ M% { N4 @& m3 h. \3 k- f9 |1 W4 T5 Y0 q9 Z
& r- a1 ]' H, x7 g: c
|
|