Spring Data - ignore parameter if it has a null value

前端 未结 9 1530
暖寄归人
暖寄归人 2020-11-29 03:59

I want to have a spring data repository interface that takes two parameters. Is there a way to make it have the following behaviour?

MyObject findByParameter         


        
9条回答
  •  粉色の甜心
    2020-11-29 04:21

    I'm not sure it is possible with repository methods naming but you can use @Query like

    (:parameterOne is null or parameter1 = :parameterOne) and (:parameterTwo is null or parameter2 = :parameterTwo)
    

提交回复
热议问题