Rest 设计子源映射
一个房客可以有很多约会 目前正在为我使用的房客预约Rest 设计子源映射,rest,spring-restcontroller,Rest,Spring Restcontroller,一个房客可以有很多约会 目前正在为我使用的房客预约 @RequestMapping(value = "/lodgers/{lodgerId}/appointments", method = RequestMethod.GET) public Lodger getAppointmentsByLogderId(@PathVariable("lodgerId") long lodgerId) { return lodgerService.getLodger(lodgerId); } 为了让所
@RequestMapping(value = "/lodgers/{lodgerId}/appointments", method = RequestMethod.GET)
public Lodger getAppointmentsByLogderId(@PathVariable("lodgerId") long lodgerId) {
return lodgerService.getLodger(lodgerId);
}
为了让所有用户都能按日期进行预约,我想我们可以从很多方面进行
我的第一个想法是为此创建一个新的资源
在任命控制人中,重新任命控制人
@RequestMapping(value = "/appointments", method = RequestMethod.GET)
public List<Appointment> getAllAppointments(@RequestParam("startDate") Date startDate, @RequestParam("endDate") Date endDate) {
...
}
@RequestMapping(value = "/lodgers/appointments", method = RequestMethod.GET)
public Lodger getAllLodgerAppointmentsByDate(@RequestParam("startDate") Date startDate, @RequestParam("endDate") Date endDate) {
...
}
对于创造来说,这是一样的
Appointment is related to a lodger
@RequestMapping(value = "/lodgers/{lodgerId}appointments", method = RequestMethod.POST)
public Lodger createAppointment(@RequestParam("lodgerId")Long lodgerId, @RequestBody Appointment appointment) {
...
}
@RequestMapping(value = "/appointments/", method = RequestMethod.POST)
public Lodger createAppointment(@RequestBody Appointment appointment) {
...
}
巫婆案更好