rest api 嵌套资源
The next important task now is to implement the sub resources of the students and the courses resource. We want all the registrations of a particular student and all the registrations for a particular course.
现在的下一个重要任务是实现学生的子资源和课程资源。 我们需要特定学生的所有注册以及特定课程的所有注册。
Add the following method in the Course
class,
在Course
类中添加以下方法,
@GET
@Produces(MediaType.APPLICATION_XML)
@Path("/{courseid}/registrations")
public List<Registration> getRegistrationWithCourseID(@PathParam("courseid") int courseID)
{
return registrationService.getRegistrationForCourse(courseID);
}
and, add the following method in the Student
class,
然后在Student
类中添加以下方法,
@Produces(MediaType.APPLICATION_XML)
@Path("/{studentid}/registrations")
public List<Registration> getRegistrationWithStudentsID(@PathParam("studentid") int studentID)
{
return registraionService.getRegistrationsForStudent(studentID);
}
翻译自: https://www.studytonight.com/rest-web-service/implementing-sub-resources
rest api 嵌套资源