|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
' U5 {! p+ |0 e1 n, y7 n9 R9 m5 a+ @! i, M# {
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:, ^. u8 g6 m* `) d/ r$ R5 r4 n
8 I3 p1 ]- G3 r! W, m# N
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
F( [! a5 r$ j: T5 Z9 a+ r. W- D8 {. ^% m+ g
4 B* c- M) i9 o$ g( @, Z/ \5 v- @ResTController
4 d- `1 [: x9 {: O* z - @RequestMapping("/user")
) _. F' ~+ m9 T9 `! t5 @ - public class UserRestController {
: B& w; Z" d; n& j - @RequestMapping("/getuser/{id}")! y; x) ]3 j" j4 O5 r. N: |! ?
- //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径
) P% i- |2 I* ~: `- E+ B - public String getUser(@PathVariable("id") Long id)
) |. h% S7 Y k7 L - {
& U8 [- x* P1 ]8 w a) o6 g0 u - User user = new User();, Y. l1 p2 S. u# x
- user.setFirstname("Donald");
& D, p3 l7 S( q" k( {5 G - user.setLastname("Xeong");
& b; {% j0 Z: {! d1 S. @+ I- v# x$ _ - user.setAge(40); y& ]6 g8 g; ^* S: x4 w- ^
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();- v0 |. x6 w2 q
- }6 i( U f# r" Q0 ?1 M& Q
- * W9 F. }/ ]6 T9 ~
- @RequestMapping(value = "/getData",method = RequestMethod.GET)
+ F+ R5 d5 h& B! P! y! A - public String getData() {: Z. U# ?. h7 o6 R, ^( ^' T" \
- return "requestMethod Get";
$ K7 H( e0 i" T - }5 h/ W5 Q) Q3 x5 q2 K
- @RequestMapping(value = "/postData",method = RequestMethod.POST)( J3 f! C3 E& Y; y) W$ O( R
- public String postData()
- w& D" W6 s- q( Q/ _ - {8 D1 K3 P$ P* `$ b! O, _
- return "RequestMethod Post";
! m4 p* I( d% ]3 y9 d/ u3 t - }
- s' f+ ], H9 [4 i. `3 W. Y4 g - }6 G% I2 p0 i# b
9 a0 j$ E! B' @# ~! a% b
复制代码 & D3 Y$ C7 b% t2 d: P2 U
7 k8 ~, ?+ P" s) Z2 a
9 N7 r7 e: S0 _
9 k0 E% B5 y, m& P. W5 ^9 I7 o |
|