JPAt集成queryDSL,灵活查询 (1.基本配置)

JPA查询过于复杂,使用queryDSL配合JPA能够更灵活的使用查询功能。

1.pom配置如下:

2.使用maven的apt-maven-plugin实现查询模版的自动生成


        com.mysema.maven
        apt-maven-plugin
        1.1.3
        
            
                
                    process
                
                
                    target/generated-sources/annotations
                    com.querydsl.apt.jpa.JPAAnnotationProcessor
                
            
        
    

JPAt集成queryDSL,灵活查询 (1.基本配置)_第1张图片

maven编译后,自动生成查询模版

public class QStudent extends EntityPathBase {

    private static final long serialVersionUID = 2136978263L;

    public static final QStudent student = new QStudent("student");

    public final StringPath age = createString("age");

    public final NumberPath host = createNumber("host", Integer.class);

    public final NumberPath id = createNumber("id", Long.class);

    public final StringPath name = createString("name");

    public final StringPath sex = createString("sex");

    public final DateTimePath startDate = createDateTime("startDate", java.util.Date.class);

    public QStudent(String variable) {
        super(Student.class, forVariable(variable));
    }

    public QStudent(Path path) {
        super(path.getType(), path.getMetadata());
    }

    public QStudent(PathMetadata metadata) {
        super(Student.class, metadata);
    }

JPAt集成queryDSL,灵活查询 (1.基本配置)_第2张图片

 

 

3.JPA持久层集成QueryDslPredicteExecutor接口

import com.five.fiveeducation.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;


public interface EducationDao extends JpaRepository,QueryDslPredicateExecutor {
}

完成JPA集成queryDSL的初步配置

 

你可能感兴趣的:(JPA)