正如您在下面的代碼中看到的,爲客戶提供的服務是在一個控制器中獲取一個並添加新客戶。
所以,你將有2個服務:
http://localhost:8080/customer/
http://localhost:8080/customer/(編號)
@RestController("customer")
public class SampleController {
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Customer greetings(@PathVariable("id") Long id) {
Customer customer = new Customer();
customer.setName("Eddu");
customer.setLastname("Melendez");
return customer;
}
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public void add(@RequestBody Customer customer) {
}
class Customer implements Serializable {
private String name;
private String lastname;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getLastname() {
return lastname;
}
}
}