Query using order by for sorting values in endpoint 2
£10-20 GBP
Pagado a la entrega
Hello there.
The issue I'm striving to solve is providing a sorting method using jpql, which can be demonstrated using this table:
Name | Address | City |
--------------------------
A | A | C |
C | B | B |
B | C | A |
I would like it so that when I pass in the name of a column, I will be able to order by the column for the results of all rows. So for example, if I were to order by name, then it should return A B C not A C B.
The goal I'm trying is that when I pass in a parameter for my API so:
http://localhost:8080/api/person?sorting=city
Now I understand that this could be resolved using:
http://localhost:8080/api/person?sort=city,asc
However I am unable to use the sort paramemter for this case, since I am relying on information from multiple domains. So from that I decided to see if it's possible to create a query in my repository that could be used to sort the values. This is my attempt at it so far:
@Query("SELECT p FROM DePerson p, DeClass c, DeSchool s" +
"WHERE [login to view URL] = [login to view URL] " +
"AND [login to view URL] = [login to view URL] " +
"ORDER BY :ordering")
List<DePerson> sortingAll(String sorting);
With that, I'm trying to see if then I am able to pass in this query from my repository and use it in my service method as a sorting method for the results I have when passing the endpoint:
List<PersonDTO> result = new ArrayList<>();
Page<DePerson> page;
List<DePerson> personList = [login to view URL]();
for (DePerson person: personList) {
[login to view URL](convertDTO(person));
}
return new PageImpl<>(result, pageable, [login to view URL]());
To conclude, I'm trying to create a custom sort parameter using jpql which should be apply to the results when the endpoint is called.
Nº del proyecto: #26020179
Sobre el proyecto
5 freelancers están ofertando un promedio de £20 por este trabajo
~Hi~dear! Please turn your attention to my reviews. I will show you first progress in 30 minutes. I have 7 years experience for C/C++, Java, Algorithm. I can show you my previous works. I am ready to start work now... Más
Hello there I am here to help you in project. I assure you, I will do my best to give you best output in reasonable time. I have some question related to proposal. Can you please contact me, So we can discuss in detai Más
Hi, I am from java background. And I have 6 years experience in Java Web application development. I can able to give better solution within the timeline. Please consider me.