Issue
I'm new to spring boot framework and i was developing spring boot rest API.
i have endpoint and i have query the database from spring boot
/buy?projectionId=value1&place=value2 // we can add different query parameters here
how to write a controller and service using spring boot.
Solution
you can pass multiple params in url like, for example:
http://localhost:2000/custom?brand=dell&limit=20&price=20000&sort=asc
and in order to get this query fields , you can use map like
@RequestMapping(method = RequestMethod.GET, value = "/custom")
public String controllerMethod(@RequestParam Map<String, String> customQuery) {
System.out.println("customQuery = brand " + customQuery.get("brand"));
System.out.println("customQuery = limit " + customQuery.get("limit"));
System.out.println("customQuery = price " + customQuery.get("price"));
System.out.println("customQuery = other " + customQuery.get("other"));
System.out.println("customQuery = sort " + customQuery.get("sort"));
return customQuery.toString();
}
Answered By - Nemanja
Answer Checked By - Mary Flores (JavaFixing Volunteer)