-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Practice(#6) : RestaurantRepository 설정
- Loading branch information
1 parent
16cbf1f
commit 26ca5cd
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepository.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package umc.spring.repository.restaurantRepository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import umc.spring.domain.Restaurant; | ||
|
||
public interface RestaurantRepository extends JpaRepository<Restaurant, Long>, RestaurantRepositoryCustom { | ||
} |
9 changes: 9 additions & 0 deletions
9
.../src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepositoryCustom.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package umc.spring.repository.restaurantRepository; | ||
|
||
import umc.spring.domain.Restaurant; | ||
|
||
import java.util.List; | ||
|
||
public interface RestaurantRepositoryCustom { | ||
List<Restaurant> dynamicQueryWithBooleanBuilder(String name, Float score); | ||
} |
36 changes: 36 additions & 0 deletions
36
...ng/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepositoryImpl.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package umc.spring.repository.restaurantRepository; | ||
|
||
import com.querydsl.core.BooleanBuilder; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
import umc.spring.domain.QRestaurant; | ||
import umc.spring.domain.Restaurant; | ||
|
||
|
||
import java.util.List; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class RestaurantRepositoryImpl implements RestaurantRepositoryCustom{ | ||
private final JPAQueryFactory jpaQueryFactory; | ||
private final QRestaurant restaurant = QRestaurant.restaurant; | ||
|
||
@Override | ||
public List<Restaurant> dynamicQueryWithBooleanBuilder(String name, Float score) { | ||
BooleanBuilder predicate = new BooleanBuilder(); | ||
|
||
if (name != null) { | ||
predicate.and(restaurant.name.eq(name)); | ||
} | ||
|
||
if (score != null) { | ||
predicate.and(restaurant.score.goe(4.0f)); | ||
} | ||
|
||
return jpaQueryFactory | ||
.selectFrom(restaurant) | ||
.where(predicate) | ||
.fetch(); | ||
} | ||
} |