|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
3 B6 [" G2 F1 Z& t" p& r! {7 r* t7 B7 G6 R1 k
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:; V& H/ p9 r' a' ]) j4 K9 [& f
7 b) r0 @) v0 G4 Z2 A- Q# \3 b- P+ U
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
) n! ^9 @. X! ]% I& W6 \2 \! g) l* g$ Z
- 3 R l' ]7 |+ l) ~: n
- @ResTController
2 u6 Z" `2 N& b* S - @RequestMapping("/user"): F% w+ L1 x" [; B8 {0 J
- public class UserRestController {: B B% r- \$ J2 l9 e
- @RequestMapping("/getuser/{id}")
9 Q: f. U: m! u - //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径* H5 [% ~' i8 @& U6 M# f. v
- public String getUser(@PathVariable("id") Long id) b2 w6 E* c0 }$ @" g4 `
- {
/ R: W+ X/ P% C - User user = new User();/ @* c' f% ~. l0 `, n
- user.setFirstname("Donald");3 W1 S7 s @. W& W& y5 m' ]' J2 U
- user.setLastname("Xeong");
! M# }' f- g/ [/ c; p( E! f2 ~' | G - user.setAge(40);
4 v* j4 Y, x! G7 Z4 I - return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();9 R6 [. A! V* E" ~
- }
5 m0 L* R" ?& Q; k) }: r ^8 K
2 j2 z! }( |) H( }' K- @RequestMapping(value = "/getData",method = RequestMethod.GET)
- W/ l1 F% q! ~1 C/ H6 V; l - public String getData() {' ~/ T6 O* U6 Q8 | a: E
- return "requestMethod Get";- L9 ^7 V+ u8 h: R$ J* K7 U
- }$ d$ ^! U8 J( a
- @RequestMapping(value = "/postData",method = RequestMethod.POST)5 b* K% w1 i' m3 F1 t& F- V7 {
- public String postData()
/ T/ ^& `$ B( }& z7 ^! v! a - {
7 [! T4 R8 c" Q$ o# s - return "RequestMethod Post";
. F3 c, \2 ?1 P+ r% J* x - }. H; _; @) X6 P {- T% M
- }' z4 `' V& A7 _% J
- ! |/ _5 W6 s: h: L0 V6 ~
复制代码
4 Q" ?, O! s. G2 e' G* {
# h, l5 I/ h# b7 a5 |$ @: D" I) ?' F: s
) ~: ?$ a( b6 w8 g- n |
|