1

I'm brand new to Spring Boot, and I've created a very basic REST service that uses JPA, and exposes the RepositoryRestResource for CRUD and query operations on my model:

@RepositoryRestResource
public interface CatalogueOrderRepository extends JpaRepository<CatalogueOrder, Long>,
    QuerydslPredicateExecutor<CatalogueOrder> {

}

Using this, I'm able to perform queries that involve searching for values, pagination, and ordering, for instance:

?page=0&size=5&sort=priority,desc&orderStatus=submitted

Is it possible to search for values that are not equal, without any additional work? For instance, all orders where the orderStatus is NOT equal to 'submitted'.

I notice that the Predicate interface has a not() method, though I'm not sure if it's related.

Anshul Sharma
  • 1,018
  • 3
  • 17
  • 39
robbieperry22
  • 1,753
  • 1
  • 18
  • 49

2 Answers2

1

For such cases you should do some work. There are different approaches to do that. See Spring docs and examples about JPA.

E.g. you can use @Query or specifications.

mentallurg
  • 4,967
  • 5
  • 28
  • 36
0

You can try "Query creation from method names".

Let's say you want to search Orders by orderstatus <> submitted,

List<Order> findByOrderstatusNot(String orderstatus);

Anshul Sharma
  • 1,018
  • 3
  • 17
  • 39
  • Will this also work with pagination/sorting? Would I need to also provide Sort and Pageable as parameters? – robbieperry22 May 11 '20 at 18:16
  • By sorting if you mean order by then yes you can use it Eg **findByOrderstatusOrderByOrderId**, but pagination is not going to be straightforward because that involves **limit** and **offset**. – Anshul Sharma May 12 '20 at 08:54