|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 m7 w2 y I3 V" X2 }/ A' e: d8 n4 I3 o
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:
# M. D0 p" Y6 T
" N1 R* o' V1 e* q& e; F8 Q" h@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
; I4 f$ o+ [& ?4 N- [- S0 p8 n+ b U& T" v0 ]8 |* Q
5 [- A0 L6 ^0 s- o, L; x4 U' L0 S; e- @ResTController
4 d! a2 \7 h* m& c3 x6 s - @RequestMapping("/user")- a; ?! r2 c6 H& J$ S! h+ }
- public class UserRestController {! k, Y% i+ G7 [
- @RequestMapping("/getuser/{id}")
' l" N$ m e' \ V% T/ q2 C5 C - //@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径8 H2 s+ ^" r+ i* Y
- public String getUser(@PathVariable("id") Long id)
0 I" ~; y! Z7 t" A) N+ ~ - {
; D3 h" H- V2 j) g* f - User user = new User();
+ L1 H5 c# v( m+ A1 K3 H0 t1 P( n - user.setFirstname("Donald"); R7 {! a4 _" x& {; N' [6 z @
- user.setLastname("Xeong");; ^- J K) a) S L
- user.setAge(40);: H1 y& E Y% t0 n4 [* |
- return id.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();
' Q v1 @! v& e7 [. y' \ }% d - }
7 M ]; [5 T2 g; K& ?: \ - 6 z4 H" B T. Y+ }
- @RequestMapping(value = "/getData",method = RequestMethod.GET)* H& S/ E9 }4 k9 I7 U, G
- public String getData() {
7 l4 S) c4 y m, L - return "requestMethod Get";
7 }# V' y* b/ o5 H, ? - }3 O9 N% u( N$ \$ B
- @RequestMapping(value = "/postData",method = RequestMethod.POST)
! S0 {- s5 l9 O2 X/ m j - public String postData()
6 P$ _) A, G* O - {
4 j! J( q0 J9 z6 W) D - return "RequestMethod Post";
r7 f8 F! b' m - }9 D* s/ O( r9 z6 E7 e
- }
0 \0 s, W: d4 A+ L' c7 m
. ~' w) X* V, ~( \4 F) q5 |1 `
复制代码
" ~8 l, K/ P+ i
! f! P0 Z$ `: e: G
6 d/ R5 c8 E3 K, L ~! s3 n
4 {( x0 n' w: U' q0 \ |
|