Spring Data JPA - Pass column name and value as parameters

前端 未结 3 776
长发绾君心
长发绾君心 2020-12-04 01:31

I just wanted to know how to pass column name and its value to @Query annotation in Spring Data JPA.

Basically column names will be static and we used to put every c

3条回答
  •  时光取名叫无心
    2020-12-04 02:01

    The only dynamic parameter Spring JPA supports is #{#entityName}. Dynamic column names in @Query annotations are not supported., and that is what you are trying to accomplish.

    Your only option is to construct a query manually using either QueryDSL, Specifications or Criteria API or simply by building a query string and passing it to your EntityManager. Regardless, you'll have to write code for that.

    See, for instance:

    • https://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/
    • How to add custom column name Spring Data JPA?

提交回复
热议问题