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

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

1.pom配置如下:

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

<plugin>
        <groupId>com.mysema.maven</groupId>
        <artifactId>apt-maven-plugin</artifactId>
        <version>1.1.3</version>
        <executions>
            <execution>
                <goals>
                    <goal>process</goal>
                </goals>
                <configuration>
                    <outputDirectory>target/generated-sources/annotations</outputDirectory>
                    <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

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

public class QStudent extends EntityPathBase<Student> {

    private static final long serialVersionUID = 2136978263L;

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

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

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

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

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

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

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

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

    public QStudent(Path<? extends Student> path) {
        super(path.getType(), path.getMetadata());
    }

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

 

 

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<Student,Long>,QueryDslPredicateExecutor<Student> {
}

完成JPA集成queryDSL的初步配置

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值