|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, o. z/ V6 o8 ?* ?& w, N; A9 d
0 ~* K& h( ]3 f8 \5 X. U8 h
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:1 o3 ^8 ?' B7 D" M- S- D. @
/ T9 k' s$ U7 y: M& f/ A) h
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method/ i; Y; u1 c& g( J( w t: L; _
- m" x M) c2 |6 E! Q4 Q- * A# I2 d/ W% M( s
- @ResTController
; G) a5 z, ?1 m- E - @RequestMapping("/user")! m# w) [( K& d' j4 j( s
- public class UserRestController {! y8 H/ v4 c" K3 T, a
- @RequestMapping("/getuser/{id}")
1 i, R" r' }4 }3 z: n3 `3 M - //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径
# a5 v2 u- }! y6 ?( } u | - public String getUser(@PathVariable("id") Long id)9 H! Y0 L' d1 M9 _1 i1 _/ x
- {; j; f: {' x7 K2 {1 H- c8 q3 }
- User user = new User();7 j- R ~1 x0 L$ _: K/ w, _
- user.setFirstname("Donald");
; u1 q g- ?8 F4 m0 J( X2 L - user.setLastname("Xeong");
9 k2 y$ q4 S% D- w" H4 A - user.setAge(40);
0 n$ v6 ^5 B% b* M' B - return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();
|8 G/ d' a3 \& |& X' f: ?" } - }& i! k9 }5 ^0 M) _, d% a/ s) L
+ o* f! d4 ?7 d% A3 A- @RequestMapping(value = "/getData",method = RequestMethod.GET)
" I" q8 J, R# x+ O1 s - public String getData() {
. `+ P" J* S) b& W( [ - return "requestMethod Get";
% y+ s3 @4 ?! j! f- L# q- l - }6 t; I- Q$ a( K7 A' i- f0 e
- @RequestMapping(value = "/postData",method = RequestMethod.POST)8 ]% h. @5 L+ ]. N' F( C; V
- public String postData()
- ?9 Y" r; @0 D1 t; _5 t4 |, u& ` - {
4 ?& `( ^4 K; d s - return "RequestMethod Post";+ @# A. U( n5 a
- }$ k s! v! y t! p: R
- }
( F) s# x# Q* M4 \8 V - ! a. O, |; u* v, h. I
复制代码 1 v# q9 H: G, i7 D4 \
- u7 R, n6 ^! J9 F7 x7 t# p
: b$ D2 X6 x- o. W+ e$ ?, J2 R) M9 W, p, O( n2 Q
|
|