|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
# c' ?9 U* _0 d' U) G
: f. ]' p* T% }! y% D% Z1 L) E+ }# y
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:8 v& \9 i$ F+ `% b
4 E, K: a7 x/ B1 e3 u
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
3 F; D8 I2 H* s
6 x8 y+ ?3 _0 [
. _9 I6 H2 K }- @ResTController
9 Q0 B0 M* N3 q! h- G* a$ M ]( H - @RequestMapping("/user") \/ r1 r! O* ^0 e; a
- public class UserRestController {
, C) D6 O/ m6 f. c - @RequestMapping("/getuser/{id}")
/ t- H7 ^! U- b. B# f* t: \/ I/ ?% O - //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径2 D) }- }& G, }7 a+ `3 v% B
- public String getUser(@PathVariable("id") Long id)1 |! S. N% H- Y1 m4 k/ i' W/ o& N
- {" ~1 k- V ~$ K, ~& e; g
- User user = new User();, `+ R" U( O, R6 h* E
- user.setFirstname("Donald");7 d# Q. b- ?8 O- J5 Y5 Z
- user.setLastname("Xeong");% t0 g g4 u. z B# b2 o0 u
- user.setAge(40);! z8 l6 t4 I2 {: Z2 R
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();% h& n# _: e1 F4 ~# p# M8 g/ O
- }) c8 S7 m1 v7 [% s/ D! W
+ e F6 M8 Z& Q5 Z% G7 p# O- @RequestMapping(value = "/getData",method = RequestMethod.GET)1 X/ r( ^3 @- m% F* R7 L" G
- public String getData() {
2 v2 Q! V- B, B0 W$ L4 ` - return "requestMethod Get";
$ m* _; S! ?& S& T1 k' t - }5 T6 T) P. R6 Y( g1 A
- @RequestMapping(value = "/postData",method = RequestMethod.POST)- V0 {! Z6 j, k4 }6 d: R$ |
- public String postData()6 [5 k5 P* g' k5 G
- {
' a- m* q" q7 ~6 } - return "RequestMethod Post";
8 |9 ?+ o- R; [$ V0 t8 }; i4 w( i - }1 E% B3 L: ?/ O4 I
- }) W8 P% S- S0 c% U- E: C
- : N6 _) m" k* g, W5 M! d# H
复制代码
' Q# A: i4 ]& K# o" S* p) ]2 q
* H0 |1 B1 D1 a, a4 Z# v$ L2 c& c. M( X4 H" u
3 ^- ^2 N4 k+ e |
|