Metrics
0
Watch 8 Star 36 Fork 8

薛纪克 / jpa-lambda-queryJava

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
基于spring-jpa的Lambda查询方式,能够实现通过Lambda进行条件查询,关联属性加载,关联属性的子查询 spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

jpa-lambda-query

介绍

基于spring-jpa的Lambda查询方式,能够实现通过Lambda进行条件查询,关联属性加载,关联属性的子查询

安装教程

  1. 使用Spring-starter进行安装
repositories {

    maven { url 'https://jitpack.io' }

}


com.github.xuejike.jpa-lambda-query:jpa-lambda-starter:0.1

  1. 手动安装 2.1. 引入依赖
com.github.xuejike.jpa-lambda-query:jpa-lambda-core:0.1.1

2.2. 初始化

        JpaQuerys.setEntityManager(entityManager);

使用说明

  1. 简单的查询语句
        //正常查询
        JpaLambdaQuery<User> userQuery = JpaQuerys.lambda(User.class);
        List<User> list = userQuery.eq(User::getUsername, "111")
                .gt(User::getCreateTime, LocalDateTime.now())
                .list();
  1. 嵌套的Or And查询语句
 List<User> list1 = JpaQuerys.lambda(User.class)
                .eq(User::getUsername, "123")
                .orEq(User::getUsername, "456")
                .or(or->or.eq(User::getUsername,"lll").eq(User::getPwd,"456"))
                .list();
  1. 分页查询
     Page<User> userPage = JpaQuerys
                .lambda(User.class, entityManager)
                .pageList(new Page(1, 10));
  1. 加载关联数据
        List<User> list1 = JpaQuerys.lambda(User.class)
                .eq(User::getUsername, "123")
                .loadJoin(User::getDept).list();
  1. 使用关联属性进行关联查询
        List<User> list2 = JpaQuerys.lambda(User.class)
                .subQuery(User::getDept, lambda -> lambda.eq(Dept::getId, 1)).list();

Comments ( 10 )

You need to Sign in for post a comment

Help Search