I have an entity class "Employee", Spring Data Rest returns all employees when I use a Get request on the path "../employees". By default it creates also links to @OneToMany relations. For example
"_links": {
"self": {
"href": "http://localhost:9000/mep/api/employees/1003"
},
"employee": {
"href": "http://localhost:9000/mep/api/employees/1003"
},
"assignmentProjectEmployeeSet": {
"href": "http://localhost:9000/mep/api/employees/1003/assignmentProjectEmployeeSet"
}
}
Is a part of the output. Now I filter this list with specifications in the follwing class.
@Service
public class EmployeeFilterService {
public Resources<Employee> getFilteredEmployees(Employee toBeFilteredEmployee) {
List<Employee> filteredEmployees = employeeRepository.findAll(
// filter stuff
);
List<Resource<Employee>> filteredEmployeesResources = new ArrayList<>();
for (Employee e : filteredEmployees) {
Resource<Employee> resource = new Resource<>(e);
filteredEmployeesResources.add(resource);
}
return new Resources(filteredEmployeesResources);
}
}
Unfortunately, this return no links. I know, that I can add links manually, but Spring Data Rest is able to create the missing links. How can I use this default behaviour?
I read something about PageResources, but I am not sure if this is the solution.
Thanks for any help Matthias