|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
1 B/ } A9 V; W: C4 F( R' t7 X2 k8 I+ H$ m' U/ `& _- Q
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:
3 Y8 r# ~5 J7 t! ]2 C6 D- x2 H5 b
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
5 e! h+ }; f/ x. W
( x; \9 y* ]" C- w% u4 Q/ d
& m; n7 |; b' v5 z. A5 F" m- @ResTController
p* x4 j. |2 U+ v: i* w - @RequestMapping("/user")( W! C4 @/ k* u a" i4 h
- public class UserRestController {
8 @6 `7 [5 E8 C# i. J - @RequestMapping("/getuser/{id}")
% m1 S; n+ q" H. ?1 s9 R - //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径5 B; U6 M" ^' }
- public String getUser(@PathVariable("id") Long id)$ d* h# s0 R W, ]" l" G$ O& h
- {8 {/ b- F" I9 B9 t& G* Y* V' w
- User user = new User();
2 e4 [9 A2 |4 R# f4 U4 \* ? - user.setFirstname("Donald");4 F# i4 J, R' A0 M- i
- user.setLastname("Xeong");2 l! }# G& C8 V5 F2 _
- user.setAge(40);4 W* j2 b2 W/ J& z! |
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();) T# v. \% R% W0 ^' f: x
- }" T1 X7 d N" o6 f7 w1 V; I5 C; P
- $ d" z; m5 f% W; k
- @RequestMapping(value = "/getData",method = RequestMethod.GET)/ k8 E; t8 J- R
- public String getData() {$ R$ K! }& {3 }
- return "requestMethod Get";# A; C0 T' F: ^4 V, d
- }5 P; s; s" b& k
- @RequestMapping(value = "/postData",method = RequestMethod.POST)
, W% ^. R; @7 G5 T! ^ - public String postData()
6 a! Y0 ]0 |$ e7 {- u - {
, T* w' B& W2 K - return "RequestMethod Post";
4 { V% D" M6 p - }
0 E" ?. ~, C- z - }- v4 b N3 }& D3 N' ~. B; r
- 3 j1 v: q" \8 c6 N a8 J) D" c
复制代码
8 h/ U: z% M7 a2 |0 M, `- W3 l
! z9 e5 }/ N/ P* j* E& b2 F/ d5 x$ O
* m+ Y* X9 {. _2 E& s; e
|
|