|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
: J! ^) n& T! i' v& `/ ~: J! _7 g! W2 d& V
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:/ }; P% J$ f6 W$ c5 j% F5 H' `6 [
& a3 }( M( s, I2 }@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method3 Y8 A1 I# u4 S2 q: F
) i, z! X7 i5 q: |- A9 _$ q( [- + J$ P+ B b; E& Z+ b' I
- @ResTController
- |$ l! d" I; y - @RequestMapping("/user")
( r4 H1 M2 s0 a) r* z3 J/ i - public class UserRestController {
: f3 {* _* _: ]- r0 E - @RequestMapping("/getuser/{id}"), }- a3 Y+ ^* C
- //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径
5 @ t' [/ }6 g. f$ U3 I - public String getUser(@PathVariable("id") Long id)
7 ^# L" [, @. P% S, _! d ~3 G7 { - {6 W2 D/ D, E2 C7 q+ ?1 Y: p; R7 B
- User user = new User();
" l6 M- F, f' I3 T& \ - user.setFirstname("Donald");+ y3 J: `6 W7 R
- user.setLastname("Xeong");
; I. a: V4 f) G6 _3 v - user.setAge(40);& @& g0 K2 J8 D9 o8 k5 a: K6 t
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();8 O0 u# |: l1 c, H4 D( t
- }
0 N! \* F. A' L$ q
. [5 q% z8 Q4 X Y; T" U- @RequestMapping(value = "/getData",method = RequestMethod.GET)5 Y' j9 H$ Z G; |& w, m
- public String getData() {1 ]* k& f1 p/ t# L, v8 Q
- return "requestMethod Get";) ~4 ^( r( |, m3 d0 G2 u2 k+ \* K
- }
8 A- o1 s/ x$ I8 ~- D0 E - @RequestMapping(value = "/postData",method = RequestMethod.POST)
1 ]" N g' ^" y, X( B% ^ - public String postData()5 O' s2 ^6 |7 _2 K/ ^ Z2 f8 ^. V3 I9 G
- {
4 D# x4 n* m& t. { - return "RequestMethod Post";
. `; D2 j' g' c6 r2 e. Y) E% V - }" s. _& d9 b0 p
- } B O* g2 K" B8 o
- * _0 o; t* E. S" L, {: R' `, a# w
复制代码 6 T% l6 \) M# q z: b
1 A" b3 P6 E4 B' i
8 R% B; M$ r( B( ]- Z' g+ h& q4 n+ _6 x8 p; N! G, N
|
|