|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
. G* m. \3 d& J/ C3 R: k. X( P
" O0 t5 Z* D" ^" G+ H# ]@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:
% k, ~, M9 Y8 v: s) ^: d' S8 ?, Q4 Q* Z8 d, C! Y# c" x- j3 X4 n( K$ x
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method+ P: }' s% | A) H, N% J0 o
2 a+ |) t# R+ ~2 i( x, i$ k
4 X+ \# k3 J$ ?* A; G, R* P }9 {8 q- @ResTController
, G% V6 t. M; [* T - @RequestMapping("/user")
$ s) F3 y+ s, N$ A* Q( W& c - public class UserRestController {5 Y8 N& ~. |0 ^5 Y- B- ]
- @RequestMapping("/getuser/{id}")5 x0 ?5 M f0 P: s x
- //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径. f+ C* N* j2 e: }1 K( P, x
- public String getUser(@PathVariable("id") Long id): \( d) D$ s4 P% |) U) Z3 z
- {
0 h: @) s1 G( r4 y0 u - User user = new User();3 o% H1 s; j. v# h
- user.setFirstname("Donald");( _2 V0 c" ?- t- [3 j
- user.setLastname("Xeong");1 Y1 w6 U% J. ~' O( q
- user.setAge(40);
5 Y( w5 m: K( l, y& ] - return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();
* t+ h' K) O& p6 r5 q% Z, `$ U# y - }' A$ R+ a; `0 y
( h. Q) [( S5 b: w' L% f Q- @RequestMapping(value = "/getData",method = RequestMethod.GET)8 W6 C. p0 ?/ o% t9 g
- public String getData() {
! r# K$ n( ]" C0 w$ L! H - return "requestMethod Get";9 C8 T& a) p/ M/ x, @: n# w
- }
6 R) g) j5 o0 w$ I/ v, P T1 B - @RequestMapping(value = "/postData",method = RequestMethod.POST)
: B, `1 d5 w" j( E; l3 v0 a - public String postData()0 k/ Y! D; O1 k/ m8 L
- {
0 }6 G$ c! z. g - return "RequestMethod Post";2 M6 w! p) F2 G- l
- }
0 d% T; r& e$ j$ } - }$ Q2 p+ r4 R; x0 c- P! z
$ \8 W @7 B/ a- x
复制代码 $ c) @- D& z( Q+ [; o# I7 m" k. A
/ j+ b0 O9 W, _3 S9 F! j4 Q' B& L% J
& \: _! X2 N1 K7 }5 o+ _# W! H* l6 ]/ e+ u
|
|