正如您在下面的代码中看到的,为客户提供的服务是在一个控制器中获取一个并添加新客户。
所以,你将有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;
}
}
}