|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
% S7 p. b3 F. s( e
/ v r3 h- w# `$ V6 O f@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:
* \9 ]( x+ K5 Q: }2 _) r; u
Q5 m! e- V& h) i/ _$ b1 A@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
: W, @* U. U# } H1 @/ E# i/ z4 f4 ]2 P0 s# T2 Y
- 5 O* v" A+ L/ y! Y7 [
- @ResTController' b) N3 T6 Y8 R1 u! `/ l, s
- @RequestMapping("/user")+ k2 n7 K2 S9 k# @! v/ y
- public class UserRestController {
, O: Z7 U: C1 d4 A4 u0 r - @RequestMapping("/getuser/{id}")
8 B1 \9 @- ^0 P) a - //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径
& Z" n$ L6 n( j; C A% P - public String getUser(@PathVariable("id") Long id)
4 k3 f' u) H- @4 `# D) ^% j - {/ t. V4 }8 Q( d7 ~. o2 ^3 H3 U
- User user = new User();
8 O' _5 v D5 x' {1 c2 Y! M - user.setFirstname("Donald"); I% y3 `/ t* ~* i$ G. H9 {! J
- user.setLastname("Xeong");
. M3 [8 B2 M+ I( J0 Z7 _ - user.setAge(40);( g& j" L& b& m: x& f1 y
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();
" p3 g) J1 x: O+ l- @2 E. x; b - }
3 s& |; l9 A! P
: W& Q, n/ d( b9 x6 Q- @RequestMapping(value = "/getData",method = RequestMethod.GET)6 S. M7 |( Y7 j9 n- y
- public String getData() {% L/ [% x- E ]) J5 q
- return "requestMethod Get";4 Y) F4 a8 d; `
- }
1 Q: }; N. u* \ - @RequestMapping(value = "/postData",method = RequestMethod.POST)
k% l$ M% P+ \2 D* t2 z3 r* B% H - public String postData()
3 t; G; r% z9 O; m - {
- p, k$ G- l: l9 Y$ j& B - return "RequestMethod Post";5 x' g0 m1 m8 H# a0 X) f
- }
8 h' m% M3 q# ^% v* T - }
( ?7 \* ~' s% M* Q - " m# s/ Q- v% v3 q! m- F b5 g
复制代码
6 d }- @# ?2 s/ @% ^4 p) J' |2 O& _1 C k# {
9 ]% y7 c1 C" X8 O# Y) I
+ |" ^5 E* P& ~4 y |
|