Skip to content

Commit b2a3cf9

Browse files
committed
更新样例
1 parent be37128 commit b2a3cf9

4 files changed

Lines changed: 97 additions & 2 deletions

File tree

Chapter1/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<artifactId>spring-boot-starter-web</artifactId>
4141
</dependency>
4242

43+
4344
</dependencies>
4445

4546
<build>

Chapter1/src/main/java/com/didispace/Chapter1Application.java renamed to Chapter1/src/main/java/com/didispace/Application.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55

66
@SpringBootApplication
7-
public class Chapter1Application {
7+
public class Application {
88

99
public static void main(String[] args) {
10-
SpringApplication.run(Chapter1Application.class, args);
10+
11+
SpringApplication.run(Application.class, args);
12+
1113
}
1214

1315
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.didispace.domain;
2+
3+
/**
4+
* @author didi
5+
* @version 1.0.0
6+
* @date 16/3/1 下午12:21.
7+
*/
8+
public class User {
9+
10+
private Long id;
11+
private String name;
12+
private Integer age;
13+
14+
public Long getId() {
15+
return id;
16+
}
17+
18+
public void setId(Long id) {
19+
this.id = id;
20+
}
21+
22+
public String getName() {
23+
return name;
24+
}
25+
26+
public void setName(String name) {
27+
this.name = name;
28+
}
29+
30+
public Integer getAge() {
31+
return age;
32+
}
33+
34+
public void setAge(Integer age) {
35+
this.age = age;
36+
}
37+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)