How can I add columns dynamically to a Spring Data JPA @Query

后端 未结 3 1079
-上瘾入骨i
-上瘾入骨i 2021-01-23 03:43

Consider the following method on a Spring Data JPA interface:

@Query(\"select distinct :columnName from Item i\")
List findByName(@Param(\"columnName         


        
3条回答
  •  孤独总比滥情好
    2021-01-23 04:27

    You can't. You'll have to implement such a method by yourself. And you won't be able to use parameters: you'll have to use String concatenation or the criteria API. What you'll pass won't be a column name but a field/property name. And it won't return a List, since you only select one field.

提交回复
热议问题