Frühlingsdaten Ruhe Beziehungen
/*when working with relationships in spring data rest it's supper easy if you
understand whats happening for example:
let's say we have an Entity Student*/
public class Student{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@OneToMany
private set<Course> coursesList;
}
public class Courses{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@OneToMany
private set<Student> studentList;
}
/* this means that a new url will be generated by spring data rest
/student/coursesList and /courses/studentList and with thouse assosiation
we can start sending POST request to add relationship or PUT request to replace
a relationship /*
/* to add a student to a list of courses you can send a POST request for example
to /courses/{courseID}/studentList/ and this request must have a
Content-Type:text/uri-list in the header and the body must be a plain text
containing the student url /student/{id} */
/*hope this explains every thing for you */
Happy Coding (●'◡'●)
Wa7ch Tennin