简体   繁体   中英

How to use Q Classes of Querydsl?

I want to use QueryDSL with JPA and I plugged in apt-maven successfully.

Pom.xml;

     <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </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/java</outputDirectory>
                            <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor </processor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Also it generated the Q classes of domain classess successfully too but when I import com.buraku.netas.domain.QUser; , it throws an error and can't find Q classes.

Here's how my folder structure looks like after I run mvn install ;

在此处输入图片说明

As you see Q classes are generated but what else should I do to use them?

First, add implements QuerydslPredicateExecutor<User> to interface UserRepository .

Second, create a method which returns com.querydsl.core.types.Predicate and build a query(JPQL) using BooleanBuilder and Q-classes .

You might refer to my sample-jpa code on github.

jpa-sample-code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM