11 Temmuz 2018 Çarşamba

SpringData QuerydslBinderCustomizer Arayüzü

Giriş
Şu satırı dahil ederiz.
import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
import org.springframework.data.querydsl.binding.QuerydslBindings;
customize metodu
Şöyle yaparız.
public interface ExpensesRepository extends PagingAndSortingRepository<Expenses, Long> ,
  QueryDslPredicateExecutor<Expenses>, QuerydslBinderCustomizer<QExpenses> {
  @Override
  default void customize(QuerydslBindings bindings, QExpenses expenses) {
    //change based on request
    bindings.bind(expenses.date).all((path, value) -> {
      Iterator<? extends Date> it = value.iterator();
      return path.between(it.next(), it.next());
    });
    bindings.bind(expenses.doctor).first(( path,value) -> path.eq(value));
    bindings.bind(expenses.title).first(( path,value) -> path.containsIgnoreCase(value));
    bindings.bind(expenses.amount).first(( path,value) -> path.eq(value));
    bindings.bind(expenses.description).first(( path,value) ->
      path.containsIgnoreCase(value));
    bindings.bind(expenses.purpose).first(( path,value) ->
      path.containsIgnoreCase(value));

  }
  ...

}

Hiç yorum yok:

Yorum Gönder