How to add custom method to Spring Data JPA

后端 未结 12 1898
盖世英雄少女心
盖世英雄少女心 2020-11-22 12:58

I am looking into Spring Data JPA. Consider the below example where I will get all the crud and finder functionality working by default and if I want to customize a finder t

12条回答
  •  渐次进展
    2020-11-22 13:31

    Considering your code snippet, please note that you can only pass Native objects to the findBy### method, lets say you want to load a list of accounts that belongs certain costumers, one solution is to do this,

    @Query("Select a from Account a where a."#nameoffield"=?1")
    List findByCustomer(String "#nameoffield");
    

    Make sue the name of the table to be queried is thesame as the Entity class. For further implementations please take a look at this

提交回复
热议问题