|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
) }, j: D: Y/ T$ M1 v& b
2 l2 ^1 v% F5 a$ N: R8 ]@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:
0 W3 H, _- K; L- g3 C5 m4 Y' p& m/ ^% y y, I5 N, A
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method/ l" [4 C$ B4 L0 o
6 B4 i9 Q: ]* [5 \0 z n0 l- % h( r; ? X3 p
- @ResTController7 K3 J- d# T" h9 S
- @RequestMapping("/user") E; V9 m. B8 u) o& F5 y. @
- public class UserRestController {5 d) E: P5 N! ~& f% V$ q
- @RequestMapping("/getuser/{id}")
% _4 K( z/ a o( l1 I3 R) E) v - //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径) L8 @7 S. C9 m- D* _* Q
- public String getUser(@PathVariable("id") Long id)+ J$ A. I4 B% e/ F) \1 M2 H! a
- {
F/ }$ v* Y7 f; D/ b+ Q( o - User user = new User();, Y$ z. i$ N5 _5 {2 f6 w/ L
- user.setFirstname("Donald");/ f' l Z: T2 g/ r8 X3 ^
- user.setLastname("Xeong");% C1 f" n6 _% E7 V `/ [0 o+ R
- user.setAge(40);; J& {* C0 B6 V( @2 I, X
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();5 ?8 e& V' ?( V, Q7 p
- }
7 W; l R2 R" F$ _; t" |6 v9 }
) x1 Q9 P" R" a8 ]" C8 w- @RequestMapping(value = "/getData",method = RequestMethod.GET)
* j8 }* U' n( k3 k' g U - public String getData() {
0 ]1 C! b" }4 d4 s - return "requestMethod Get";
6 |. E- C0 a1 H- c, _# P- A' D - }
5 q) S6 U1 S, ]* v - @RequestMapping(value = "/postData",method = RequestMethod.POST)
( C. B% L; c0 F$ @3 {) b# g q1 x2 L - public String postData()
* `2 a4 m$ y/ H0 g7 D1 m0 g - {% f. S. Y* a5 P$ f- l
- return "RequestMethod Post";
0 O% T* u7 }6 d, }7 [: D: Y) r - }4 D3 L) d7 [) d2 \) ?
- }
1 Z8 T8 Q) `. N9 {
- G" g9 F- R! F/ `( O& H2 r" ?/ {
复制代码
' u" c2 h! s& ~& {- R! K' `# Z4 o" Q7 P( Y# A
" ~3 k p) u/ [& j* y& B2 s
# F- K8 u& s4 y" |2 q |
|