|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
% P- D/ H7 n2 T- B8 V+ V8 t
% Y* Y" H( V0 k' _3 I; Z% S
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:" }- b4 ~* T$ r1 n5 R1 D
/ H. c* v, e+ t0 w
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
3 I/ z% v6 h' k2 u5 [
4 e9 o- L; ?' J3 e/ @' w1 }. P3 R$ |- 6 Z$ x! x- l7 N. h1 C/ g8 w- ^
- @ResTController
$ `& s3 m; }- I& ]/ `0 L3 g& e9 V: v - @RequestMapping("/user")+ Z3 @" s- ?6 F+ b5 _
- public class UserRestController {% c' p$ D. m+ s, d: K
- @RequestMapping("/getuser/{id}")& o( V# a( \& ?4 s) C
- //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径
$ F4 O9 k4 U9 z* ~4 [" m - public String getUser(@PathVariable("id") Long id)' N1 ^: m% e& a6 ], y' j3 R
- {
/ D9 \9 `$ f) [% F) o( z! _ - User user = new User();
% q e1 [0 G3 p% j - user.setFirstname("Donald");
$ ~( q# I! M s - user.setLastname("Xeong");8 d" [, a$ @# Y! [4 [8 t
- user.setAge(40);+ n- w! d- y7 d# J9 N% ]' T
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();& X* t0 l8 ]( i: [
- }
% b% Q9 s1 a# E
' _$ H8 a. R% ?9 d M* u9 j6 K- @RequestMapping(value = "/getData",method = RequestMethod.GET)* E, j. Y5 _8 c9 S' B8 ?4 o
- public String getData() { {! |* A% B! r; g& O, i
- return "requestMethod Get";' D* \+ E8 a3 p
- }0 a: c, A+ b& l2 j1 L4 d6 o
- @RequestMapping(value = "/postData",method = RequestMethod.POST)
; G% C+ P A' g! _4 \9 S - public String postData()
* O' I4 ]* t0 H - {3 M* p. U: J' y. P$ E
- return "RequestMethod Post";
5 W8 s( g! K# }2 E - } t3 [ T2 V8 Q* z! \
- }
3 p; h1 c2 [( u) ~' ^6 F$ l - / `; d. S8 H; h& x* t$ E
复制代码
! X! N9 L; F: [. b* E" k
7 E! F7 f# v( T. g& H' U# W8 R
x9 R0 n5 S* [( }7 Q |
|