|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; Q! e# A! u3 i0 ~9 |
+ V& {1 r7 t+ ` E7 m( L; a) C@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:
/ j+ g& s% p+ R; u" P% M7 ^* O3 y1 ~) O
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
, h7 q x3 ~5 W" `* A9 W$ f0 f6 `0 @* f
2 L. H6 L2 Q" u" {8 P- @ResTController
3 E6 ?, `# V& i1 P - @RequestMapping("/user")
" f( v7 M8 z9 \" J( H8 b4 } - public class UserRestController {- _/ v+ K' b# C4 e
- @RequestMapping("/getuser/{id}")
$ V% Z3 ~9 h7 {$ U" U - //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径4 Y, P& P9 y/ h$ r- \0 G- e6 K7 t
- public String getUser(@PathVariable("id") Long id)
. N4 G" C( }( Q' N - {
& A3 f" Z$ {$ j: a' r7 K - User user = new User();
' s% w0 |# {/ t5 G* W - user.setFirstname("Donald");
]& |" U" [5 b2 s7 m: k - user.setLastname("Xeong");
; Q0 d$ h) m) c$ c0 _ - user.setAge(40);9 \6 @5 o1 x4 X9 ]5 T
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();
6 |0 ^* ]1 `( p2 B2 a6 c u - }( p. W) n7 b) a" W
- 9 u, k1 A# p9 J& B) f! i
- @RequestMapping(value = "/getData",method = RequestMethod.GET)
6 M* V2 `) _/ D l - public String getData() {
4 k3 p! C K4 B; b3 Q8 g# s6 ]/ y; ]) C - return "requestMethod Get";
% ?3 o# X0 g2 Y; {1 `: N& L1 Z; K - }
) A) I3 _: d1 X' i - @RequestMapping(value = "/postData",method = RequestMethod.POST)
+ ]2 n4 m6 @8 z5 E* m4 E - public String postData()
4 D7 c( e0 o+ n3 f - {
8 B/ h$ X% t/ k) D( a% C - return "RequestMethod Post";
9 G9 {: x. c) v i" J5 \ - }* D D# s# q( b6 Q( X9 C# j
- }
5 `: W# R# G+ L! e0 C: i1 z) O
7 o- {3 } W' t4 p2 L
复制代码
/ `8 p+ L J) }) ?4 Z5 u( |+ f5 N* F" L3 e: Q5 M7 U
5 f+ ]* q$ V9 I0 s4 K
+ j& G) g3 @, B9 p: N0 c |
|