0

I want to Create custom query which will depend on number of Fields will get from @RequestParam Like

public List<User> method(
  @RequestParam("key") String []key,
  @RequestParam("value") String [] value){}

Then I have to create a query in Service layer according to number of element I'll get in key and value

For example in first array(in key) element is "UserName" then in value array I'll get (value of username)

In these arrays, the number of fields will be dynamic. After that I have to pass that whole query String in Repository of Springboot & retrieve data from mongodb database.

2

1 Answer 1

1

Firstly, I would use a map instead of two arrays to map the request params.

For dynamic queries you have to use query criteria or HQL.

Then based on the map entries I would build the query criteria from JPA.

There is already a lot of material on how to build a criteria.

Sign up to request clarification or add additional context in comments.

6 Comments

can you tell me example of query criteria for this problem or code snippet with atleaset 2 key value pair ,Because i'm totally new in Mongo & query criteria
And i thing JPA is only for Rdbms not for NoSql
map as request param is here: stackoverflow.com/questions/47418489/…
can anyone tell me logic as in code of this because i'm not able to get the solution of this problem
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.