JPA - FindByExample

前端 未结 7 1990
故里飘歌
故里飘歌 2020-12-08 04:29

Does anyone have a good example for how to do a findByExample in JPA that will work within a generic DAO via reflection for any entity type? I know I can do it via my prov

7条回答
  •  温柔的废话
    2020-12-08 05:27

    https://github.com/superbiger/sbiger-jpa-qbe

    I'think query by example with single table like mybatis is easy to use

    base on jpa we can also support Join/GroupBy like this:

    /*
    SQL:
        select * from
            user 
        where
            id=1 
            or id=2 
        group by  
            id,  
            name   
        order by  
            id asc,
            name asc 
        limit ?
    */
    public List findAll(){
        Example example = ExampleBuilder.create();
        example.or()
                .andEqual("id", 1)
                .orEqual("id", 2);
        example.groupBy("id","name");
        example.asc("id","name");
        return userReponsitory.findAll(example, new PageRequest(0, 1));
    }
    

    Features now:

    • Support and/or logic operation
    • Support is(Empty/Boolean/Null)
    • Support Equal/NotEqual/In/NotIn/Like/NotLike
    • Support gt/ge/lt/le/between
    • Support join query
    • Support group by
    • Support custom specification.
    • Support pagination
      more features coming soon……

提交回复
热议问题