|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
) a7 ~' J/ `8 ~
5 [5 y4 T* T8 C@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:
2 T7 O: k6 I* H
! f5 P$ L- B7 O9 ~1 G) R" C@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method- ^6 \+ ^6 N9 H+ U4 ]3 M& E0 u
7 E6 u8 A, M2 n+ D- Z2 [" M
0 f. r2 q2 D2 V6 v c- @ResTController; w) R8 ~7 i2 e9 a. p2 J# K6 ]' n
- @RequestMapping("/user")
+ d8 T) Y2 R' U q, @- ?% }" \& B - public class UserRestController {
* a- B8 b/ \: o) D - @RequestMapping("/getuser/{id}")
8 R' d+ z6 `* M, {) S, Z$ c - //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径
, s% v' {0 b; Q - public String getUser(@PathVariable("id") Long id)+ u0 M8 U" ^$ A, P I
- {9 w( J2 o1 r c0 ^1 V
- User user = new User();' m* V+ F; x8 B" x
- user.setFirstname("Donald");
' l, h1 x; D# v$ z: A5 Q - user.setLastname("Xeong");
, n) b- i9 t3 R" \0 g - user.setAge(40);- V! J7 p" {0 m4 y
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();
7 ?. j8 `4 O: [7 x9 Q - }- I8 g0 ]4 X. b+ y( s3 @7 n
- % u8 A. q4 i- s' y! s! N* n; b- ~
- @RequestMapping(value = "/getData",method = RequestMethod.GET)6 d. M B; L$ ~4 ]7 ^7 ~
- public String getData() {
: J6 {$ ?4 ^: b$ v+ o9 W8 u - return "requestMethod Get";& S+ P* \& w- ~& ^9 U
- }# \; @- {) w: K' m- }& y
- @RequestMapping(value = "/postData",method = RequestMethod.POST)
4 E1 v( K. R+ b2 @! P% m0 ~ - public String postData()
8 N3 A9 d! d8 @ - {% Y7 {6 R5 N) \. F9 y, Q( ~
- return "RequestMethod Post";
5 {, X: C& x1 R# E' e - }
- o# _3 X9 g, i4 d1 m - }9 G, u( G! S" i( e
- - ]& o/ k" @ t" K2 F6 ]7 c4 e
复制代码
, `, ? R2 e7 }
* J+ @! @$ ^2 G: Q/ ~# l- a$ o4 ^
I$ R; z+ K) q3 q+ M, z
|
|