|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
+ j5 ~. k5 d3 H, K+ H ~* h# M
1 C! h2 ]- O( J( ]$ q5 ?4 n@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:
( I+ c& {9 y' J% ]' }/ U
: m. \1 @& A& }5 H5 F@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method7 n; `5 h* O! `$ ?& K. j" Y! y
; r- x' v' e# ]$ w
% l+ K' ]! U1 Z: z8 Q- @ResTController% ?) d5 V7 m6 N+ w8 K
- @RequestMapping("/user")
; |: d! I; D5 i2 }- k - public class UserRestController {& `* }3 t T/ b/ ?' T! Y, y
- @RequestMapping("/getuser/{id}")
8 c/ L* t( }; p0 F: W. M0 O - //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径0 H# n* Y& p0 y/ D8 E1 W
- public String getUser(@PathVariable("id") Long id)
( G% p( R3 p9 k+ `8 v - {
7 w; P; D( S2 W! _ - User user = new User();) V8 ]1 e0 C, h8 o& s! @' ^
- user.setFirstname("Donald");. q- L+ I; D& L1 o6 e
- user.setLastname("Xeong");
8 }5 f- D, V( S: s0 o3 C% M - user.setAge(40);
/ n! v. ]% ^. q3 r5 d5 Q - return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();3 u* {/ ]* t) ~- t
- }8 J& ?4 `& C/ }
% f, k" B; K9 _! |0 w" K- @RequestMapping(value = "/getData",method = RequestMethod.GET)4 U) C& N4 c% J e( @% P% V+ L6 O
- public String getData() {
& E' I/ m. q5 t( f5 ], Z - return "requestMethod Get";
! A2 r! [6 U: X# J! p - }2 e. @$ Q' K+ v* R
- @RequestMapping(value = "/postData",method = RequestMethod.POST) U- n. y, N9 ]* r7 O
- public String postData()7 F0 |5 ]6 n3 z4 d
- {
6 C% l" H2 O* J* s1 U - return "RequestMethod Post";
* e& N* G( T) [$ X - }
! [7 J. x. b p" @6 v - }- N4 l P( Z/ D7 f% @- t
- ; A2 j3 l+ N4 K. J
复制代码
& F! c: C+ P+ \, x2 p# C
/ o( M7 y3 g+ W; E& q z6 E% s0 n) W& a% s3 F3 o
# H1 e' s! c6 G* {8 y! [
|
|