|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
) }) k( B# [5 Z1 @/ a$ S
& E' B, R; Y. Y@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:5 U5 ^& d) r6 C$ Q
5 G0 y8 V" B( l: M2 E9 i; r' ]* u@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
7 c9 G" U0 V, O0 e* p N* Z5 F/ H
+ \7 ~# n9 Z& w3 Q3 v; T* \- @ResTController
" n% y2 J. Q3 g: @ p - @RequestMapping("/user")! d% C2 V. h, n! j$ u$ [$ a0 m
- public class UserRestController {( N3 f- E [% r( @& _- z0 G" s
- @RequestMapping("/getuser/{id}"), Q& ?! ?' R& E4 m2 l+ \) p# Y
- //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径
, q/ X! f! g' L B' _- E - public String getUser(@PathVariable("id") Long id)3 J& M1 w# A7 g
- {2 W* l1 m F( B( ?( ^
- User user = new User();
& a( G5 M, N: S) k- h+ I/ g - user.setFirstname("Donald");
! n6 W/ m1 L6 g2 I- a - user.setLastname("Xeong");! \; Z# q6 ^- `, ]1 I7 a; u! R! K
- user.setAge(40); C* v& I5 F, ]$ A
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();8 d9 q% _: c$ t; y4 H9 t
- }+ M* O+ o& T& O% t$ e
$ W9 g7 l# R6 y# p: n8 Q5 H- @RequestMapping(value = "/getData",method = RequestMethod.GET)8 v" M# i8 f' Z8 Y* O( H2 a
- public String getData() {
$ n" ]4 Q5 D5 @9 Y - return "requestMethod Get";% [" {$ N4 @- w
- }
# \- w7 H4 X x. N9 a* h8 i - @RequestMapping(value = "/postData",method = RequestMethod.POST) p' U) x e7 w0 `, @/ ^4 m* d
- public String postData()
* Q: k* G% j, q. _0 V7 y - {
9 ^8 B K- w; E - return "RequestMethod Post";
4 y, j' n: j# O: A- |) w - }' m5 L" a B1 g1 ^& v- |
- }+ `% z8 q$ b" o* e" A' m
- 3 G l' d* O' i2 a* e
复制代码
4 W% `2 m0 {6 r1 Y/ m2 x
6 `7 [+ Y3 L* z3 _
9 ] ]. C9 `4 P. F6 j' Q$ k5 S
' n- O% ?7 x' t$ { |
|