|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
|9 @* G: ?- w6 N0 t* n
+ n" ]+ {" p- [& N* D% S@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:
- C8 n6 F O. {4 m, U& l C8 P
" X" s; A/ g* h& C5 ]6 D7 S@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method, n" k" F$ u y, J: R+ E8 j
+ C, W. b4 J0 H1 E L- 6 F$ T% {0 c o
- @ResTController
8 B* E0 K- n! E9 }& e - @RequestMapping("/user")/ Z8 G r& _5 L6 d% k
- public class UserRestController {
' h) W/ ` B3 F+ R - @RequestMapping("/getuser/{id}")2 I% ] B4 @, X" |' d8 s
- //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径' k, U0 l, n+ ~
- public String getUser(@PathVariable("id") Long id)
. q! r7 [/ y0 \/ `% X; g - {
7 t1 `/ P8 P0 D - User user = new User();
, w* {* E9 L3 k* G; o. |& f - user.setFirstname("Donald");
% A( Y! k+ s, L% ~ - user.setLastname("Xeong");, a7 u$ s x7 s9 r! {8 q
- user.setAge(40);4 @, w) M5 _, a% V- y; r6 n
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();4 H+ @. \+ |& _# f: z. y
- }6 v2 k* W4 P3 E' _* V- b4 s
- $ }( _( C4 s7 R. `
- @RequestMapping(value = "/getData",method = RequestMethod.GET)4 {' o1 Y: O3 y
- public String getData() {1 t, Z4 O% }- X8 R0 ]4 a
- return "requestMethod Get";# l0 f/ \3 z/ P( F3 T" j6 ~+ `$ U
- }
, n" X" h+ [( B9 |! W: e- Z+ I - @RequestMapping(value = "/postData",method = RequestMethod.POST)$ t6 R; t: u) F0 }2 c
- public String postData()2 u {; P' N! X
- {
: F% F3 G1 c# A4 e - return "RequestMethod Post";9 A# Z. X2 I" p- i6 U' p7 j
- }; }; W2 s$ @3 O) M2 I
- }6 o( K: [, b5 i9 G4 c7 `
/ o* ^0 H+ j7 G( q& r
复制代码 % H [7 p) Z+ s& R( z7 b: Z+ G
% @7 x* I9 g+ D1 X. N
5 c. ]5 G' o, x3 L
/ K: [" T0 h0 m! f1 ^% V+ ` |
|