I'm using Java, Spring Boot and PostgreSQL
Right now I'm trying to send request form with multiple paramaters from website, to search the database for rows that match these parameters.
Like that
http://localhost:8080/search?vtitle=&vcompany=Epam&vcity=Kiev&vlanguage=Java
I already figured out how to get such a solid query, but there is a problem.
List<JobSite> allJobs = jobRepository.findByTitleContainingAndCompanyAndCityAndLanguage(searchForm.getVtitle(),
searchForm.getVcompany(),
searchForm.getVcity(),
searchForm.getVlanguage());
allJobs.sort(Comparator.comparing(JobSite::getTime).reversed());
model.addAttribute("jobs", allJobs);
return "index";
If i will not select one of the parameters it will not query this rows because of how findBy... method works.
If i will change code a little to
public String submit(@RequestParam MultiValueMap<String, String> params, Model model) {
I will get some freedom. But even so I can't find a way to "automatically generate" queries like
SELECT * FROM table WHERE title = 1 AND company = 1 AND city = 1 AND language = 1
SELECT * FROM table WHERE company = 1 AND city = 1 AND language = 1
SELECT * FROM table WHERE city = 1 AND language = 1
SELECT * FROM table WHERE language = 1
SELECT * FROM table WHERE title = 1 AND city = 1 AND language = 1
And so on.
If I will code it myself with Spring it will become a mess.
What is the best way to do such a search from site?