Last active
April 7, 2018 16:52
-
-
Save urstory/750b5033a53903e1864e9e82f82f1a16 to your computer and use it in GitHub Desktop.
spring boot 2.0 & querydsl 4.1.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.repository; | |
import com.querydsl.core.types.OrderSpecifier; | |
import com.querydsl.core.types.Predicate; | |
import org.springframework.data.domain.Sort; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import org.springframework.data.querydsl.QuerydslPredicateExecutor; | |
import org.springframework.data.repository.NoRepositoryBean; | |
import java.io.Serializable; | |
import java.util.List; | |
@NoRepositoryBean | |
public interface JpaQueryDslPredicateRepository<T, ID extends Serializable> | |
extends JpaRepository<T, ID>, QuerydslPredicateExecutor<T> { | |
@Override | |
List<T> findAll(OrderSpecifier<?>... orders); | |
@Override | |
List<T> findAll(Predicate predicate); | |
@Override | |
List<T> findAll(Predicate predicate, OrderSpecifier<?>... orders); | |
@Override | |
List<T> findAll(Predicate predicate, Sort sort); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.day29.repository; | |
import com.querydsl.core.types.dsl.BooleanExpression; | |
import examples.day29.entity.QUser; | |
import examples.day29.entity.User; | |
import org.springframework.data.domain.Page; | |
import org.springframework.data.jpa.repository.Query; | |
import org.springframework.stereotype.Repository; | |
import java.util.List; | |
public interface UserRepository | |
extends JpaQueryDslPredicateRepository<User, Long> { | |
public default List<User> getUsersByNameEqKim(){ | |
QUser qUser = QUser.user; | |
BooleanExpression eq = qUser.name.eq("kim"); | |
return findAll(eq); | |
} | |
@Query("select u from User u where u.id = ?1") | |
public User findUserById(Long id); | |
public User findUserByName(String name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment