Spring Data optional parameter in query method

后端 未结 4 1135
有刺的猬
有刺的猬 2020-12-02 22:21

I want to write some query methods in repository layer. This method must ignore null parameters. For example:

List findByBarAndGoo(Bar barParam,          


        
4条回答
  •  盖世英雄少女心
    2020-12-02 22:36

    You could code this yourself in just a few lines:

    List findByBarAndOptionalGoo(Bar bar, Goo goo) {
       return (goo == null) ? this.findByBar(bar) : this.findByBarAndGoo(bar, goo);
    }
    

    Otherwise, I don't know if Spring-Data supports this out of the box.

提交回复
热议问题