The returned subset / subcircuit using spring JPA data

I am creating a REST API using the spring framework, and have come across a not-so-interesting case that did not seem to find a solution for.

So, let's say that we have a table Table1 with columns Col1, Col2 and Col3 and we have users of access level 1,2 and 3

Access level 3 users are the only ones allowed access to Col3 along with all other columns, the rest are allowed access to anything else.

Also, I want the API to be able to return a subset of the fields based on the call, IE: if the call was called in URL / table / list? fl = col1, only Col1 will be returned.

What I need is a way to return this particular subset of data at the API level, apparently the spring JPA data does not allow the substring to return a dynamic table.

I was wondering what could be the cleanest way to do this without completely abandoning the JPA or rewriting all the functions in all entities.

+3
source share
1 answer

Let me tell you my thoughts.

What I need is a way to return this particular subset of data at the API level, obviously spring JPA data does not allow a dynamic subset of the table to be returned.

, JPA , @Query, jpql , spring List,

, , - spring Security, @PreAuthorize

@PreAuthorize("hasRole('ROLE_USER')")
public void create(Contact contact);    

, "ROLE_USER".

, , , , spring jpa .

- jpql entityManager, , @SqlResultMapping, , .

+1

All Articles