3
I need to perform a select using the spring data @Query, but I need to pass the column name by parameter
Example:
@Query("SELECT g FROM Grupo g where g.? = ?")
Page<Grupo> findTeste(String campo, String valor);
To call method I wanted to pass the column name as following:
//Pseudo code
page = grupoService.findTeste("id", "1");
page = grupoService.findTeste("nome", "asdf");
It is possible to build some method like this in spring data?
This way there is no way - not without changing the core of the framework -, the lookup of queries in spring data is in startup. What you can have is a custom repository, use Specifications, build queries dynamically, use something like querydsl, etc. If it is not mandatory to use
@Query
Then I’ll give you an answer.– Bruno César
It is not required to use @Query, I will study Specifications and the querydsl if you can send a code I appreciate.
– Jack