NingZeta-Sample-Querydsl

General usage example of querydsl with Spring JPA.

Meta-model are generated using maven plugin maven-apt-plugin.

Description:

Entity

Data File

Use-Case

Technology use

Refer to pom.xml for details.

Requirement

How to ?

1) Describe the Entiy and Annotate with @Entity.

@Entity
class Country {
   ...
}

2) Add the maven dependency.

<!-- Querydsl dependencies -->
 <dependency>
    <groupId>com.mysema.querydsl</groupId>
    <artifactId>querydsl-apt</artifactId>
    <version>${querydsl.version}</version>
</dependency>
<dependency>
    <groupId>com.mysema.querydsl</groupId>
    <artifactId>querydsl-jpa</artifactId>
    <version>${querydsl.version}</version>
</dependency>

3) Generate the meta-model using maven plugin.

<!-- Generate meta-model classes -->
<plugin>
  <groupId>com.mysema.maven</groupId>
  <artifactId>maven-apt-plugin</artifactId>
  <version>1.0.4</version>
  <executions>
    <execution>
      <phase>generate-sources</phase>
      <goals>
        <goal>process</goal>
      </goals>
      <configuration>
        <outputDirectory>generated-sources</outputDirectory>
        <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
      </configuration>
    </execution>
  </executions>
</plugin>

The generated meta-model will appears under the generated-sources at the base of the maven project. I like to use in ide with class-path so its not under target directory.

Generate the sources with mvn generate-sources

3) Now extends the custom repository with the org.springframework.data.querydsl.QueryDslPredicateExecutor.

public interface CountryRepository extends JpaRepository<Country, Long>,
                                            QueryDslPredicateExecutor<Country>{
}

Usage

mvn clean spring-boot:run and hit the url http://localhost:8080

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D