更新样例
This commit is contained in:
@@ -40,6 +40,7 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
+4
-2
@@ -4,10 +4,12 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Chapter1Application {
|
public class Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Chapter1Application.class, args);
|
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.didispace.domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author didi
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 16/3/1 下午12:21.
|
||||||
|
*/
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private Integer age;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAge(Integer age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.didispace.web;
|
||||||
|
|
||||||
|
import com.didispace.domain.User;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value="/users") // 通过这里配置使下面的映射都在/users下
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@RequestMapping(value="/", method=RequestMethod.GET)
|
||||||
|
public List<User> getUserList() {
|
||||||
|
// 处理"/users/"的GET请求,用来获取用户列表
|
||||||
|
// 还可以通过@RequestParam从页面中传递参数来进行查询条件或者翻页信息的传递
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value="/", method=RequestMethod.POST)
|
||||||
|
public User postUser(@ModelAttribute User user) {
|
||||||
|
// 处理"/users/"的POST请求,用来创建User
|
||||||
|
// 除了@ModelAttribute绑定参数之外,还可以通过@RequestParam从页面中传递参数
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value="/{id}", method=RequestMethod.GET)
|
||||||
|
public User getUser(@PathVariable Long id) {
|
||||||
|
// 处理"/users/{id}"的GET请求,用来获取url中id值的User信息
|
||||||
|
// url中的id可通过@PathVariable绑定到函数的参数中
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value="/{id}", method=RequestMethod.PUT)
|
||||||
|
public User putUser(@PathVariable Long id, @ModelAttribute User user) {
|
||||||
|
// 处理"/users/{id}"的PUT请求,用来更新User信息
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
|
||||||
|
public User deleteUser(@PathVariable Long id) {
|
||||||
|
// 处理"/users/{id}"的DELETE请求,用来删除User
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user