|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
3 N# i0 U8 O+ |
- d( I* r% x4 {8 w7 V2 B# y5 j
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:( G b! k' \5 K
1 ~7 ^& d! H; q0 _; P6 i* O
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method0 ^- g* [8 V3 |9 C# [& Y1 o" X
3 `2 v( c6 b0 {( o% A
H# Q3 i& y7 q' x/ L" @! F8 V1 n- @ResTController n- E: X- W: ?; i! [
- @RequestMapping("/user")3 l1 q* d. e* C2 R, y) ^9 t& `9 I
- public class UserRestController {
- X3 t2 ]# T$ T1 z( a' q1 a; Q - @RequestMapping("/getuser/{id}")' f4 p& c/ J' B- u/ ~
- //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径
) v! V! e' u/ P4 c3 [& S: m! k; w - public String getUser(@PathVariable("id") Long id)
/ c- \" i) _/ X$ I0 r4 l - {# r6 P# r/ I) O+ w. {! L" v
- User user = new User();
3 u* k. [) K8 G% x! [) M - user.setFirstname("Donald");
( C' `& q j6 |! E8 D/ L. n$ i: u - user.setLastname("Xeong");0 R$ {# _, [$ k4 h3 }
- user.setAge(40);% t4 c5 o- U7 z% L
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();
! h: B; C* y1 X! L+ n5 p& C - }- P7 r( ^5 ^# u" X7 B8 X/ l4 m& O
- & ~$ B8 K, [' {# g% [0 F
- @RequestMapping(value = "/getData",method = RequestMethod.GET)
! M8 a& |0 Q6 B8 V) F - public String getData() {) _; v4 |% _6 }1 T2 ~+ n
- return "requestMethod Get";
6 m- ?0 x; I+ U& Y z - }
1 p7 y; ]$ R% c/ D! } - @RequestMapping(value = "/postData",method = RequestMethod.POST)5 o( n9 c; E' ` m2 |' y2 U8 J
- public String postData()
2 Y2 ]7 F2 l; R& h3 C! S }) P - {
; r1 i$ s/ O7 c0 p - return "RequestMethod Post";4 E3 d8 U$ K) h$ h$ f
- }
8 A2 k9 L9 f. o* S - }: W8 }& p& M* a6 A2 J- G
4 Z0 A# C1 N2 k5 N/ d5 {7 n: M" y
复制代码 : @& W% g# b" w1 K$ T/ E
, z' i) } b! t: o
8 R+ O: \& i7 q1 E
. g! \$ w9 s: K) C
|
|