Spring JPA : Using Specification with Projection
You may probably know that using
I'll show you how you can easily bypass this problem using the JPA Criteria.
We begin by creating an extending global repository as follow :
You can find more information here.
2. Add our custom method
In order to limit the fields returned for each item, the consumer of my API must provide the required fields this way:
Basically, I'm defining the SELECT clause with the returned fields (cf.
😎Happy coding...
Specification
with Projection is not possible at this moment.I'll show you how you can easily bypass this problem using the JPA Criteria.
1. Create an extended repository
We begin by creating an extending global repository as follow :
You can find more information here.
2. Add our custom method
In order to limit the fields returned for each item, the consumer of my API must provide the required fields this way:
/orders?fields=productId,name,quantity
. (Best Practices)Basically, I'm defining the SELECT clause with the returned fields (cf.
getSelections()
):😎Happy coding...
Comments
Post a Comment