1+ package com .didispace .web ;
2+
3+ import com .didispace .domain .User ;
4+ import java .util .List ;
5+
6+ import org .springframework .web .bind .annotation .*;
7+
8+ @ RestController
9+ @ RequestMapping (value ="/users" ) // 通过这里配置使下面的映射都在/users下
10+ public class UserController {
11+
12+ @ RequestMapping (value ="/" , method =RequestMethod .GET )
13+ public List <User > getUserList () {
14+ // 处理"/users/"的GET请求,用来获取用户列表
15+ // 还可以通过@RequestParam从页面中传递参数来进行查询条件或者翻页信息的传递
16+
17+
18+ return null ;
19+ }
20+
21+ @ RequestMapping (value ="/" , method =RequestMethod .POST )
22+ public User postUser (@ ModelAttribute User user ) {
23+ // 处理"/users/"的POST请求,用来创建User
24+ // 除了@ModelAttribute绑定参数之外,还可以通过@RequestParam从页面中传递参数
25+
26+
27+ return null ;
28+ }
29+
30+ @ RequestMapping (value ="/{id}" , method =RequestMethod .GET )
31+ public User getUser (@ PathVariable Long id ) {
32+ // 处理"/users/{id}"的GET请求,用来获取url中id值的User信息
33+ // url中的id可通过@PathVariable绑定到函数的参数中
34+
35+
36+ return null ;
37+ }
38+
39+ @ RequestMapping (value ="/{id}" , method =RequestMethod .PUT )
40+ public User putUser (@ PathVariable Long id , @ ModelAttribute User user ) {
41+ // 处理"/users/{id}"的PUT请求,用来更新User信息
42+
43+
44+ return null ;
45+ }
46+
47+ @ RequestMapping (value ="/{id}" , method =RequestMethod .DELETE )
48+ public User deleteUser (@ PathVariable Long id ) {
49+ // 处理"/users/{id}"的DELETE请求,用来删除User
50+
51+
52+ return null ;
53+ }
54+
55+ }
0 commit comments