I want to have a spring data repository interface that takes two parameters. Is there a way to make it have the following behaviour?
MyObject findByParameter
I am not sure if its possible using Repo as a separate class but you can use StringBuilder append query with option parameter. This will definitely work
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("select p.name from personDemographic p ");
Boolean flag = true;
if(parameterOne != null){
if(flag){
queryBuilder.append("where condition...");
flag=false;
}
}
if(parameterOne != null){
if(flag){
queryBuilder.append("where condition...");
flag = false;
}else{
queryBuilder.append("and condition...");
}
Query query = entityManager.createQuery(queryBuilder.toString());