Skip to content

Querydsl support #222

Open
Open
@easybest

Description

@easybest

Querydsl is a framework that enables the construction of statically typed SQL-like queries through its fluent API.

Spring Data Mybatis offer integration with Querydsl through QuerydslPredicateExecutor, as shown in the following example:

public interface QuerydslPredicateExecutor<T> {

  Optional<T> findById(Predicate predicate);  

  Iterable<T> findAll(Predicate predicate);   

  long count(Predicate predicate);            

  boolean exists(Predicate predicate);        

  // … more functionality omitted.
}

To make use of Querydsl support, extend QuerydslPredicateExecutor on your repository interface, as shown in the following example

interface UserRepository extends CrudRepository<User, Long>, QuerydslPredicateExecutor<User> {
}

The preceding example lets you write typesafe queries using Querydsl Predicate instances, as shown in the following example:

Predicate predicate = user.firstname.equalsIgnoreCase("dave")
	.and(user.lastname.startsWithIgnoreCase("mathews"));

userRepository.findAll(predicate);

How to use?

Add dependencies to you pom.xml

                <dependency>
			<groupId>io.easybest</groupId>
			<artifactId>spring-data-mybatis-querydsl</artifactId>
			<version>${revision}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>com.querydsl</groupId>
			<artifactId>querydsl-sql</artifactId>
			<version>${querydsl}</version>
			<optional>true</optional>
		</dependency>

spring-data-mybatis-querydsl use APT to generate query code

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions