I have some params to generate different sql condition,
Condition con = DSL.trueCondition();
if (StringUtils.isNotEmpty(book.getName)) {
con = con.and(BOOK.NAME.eq(book.getName))
}
if (book.getId > 0) {
con = con.and(BOOK.ID.eq(book.getId))
}
if ...
I want to know if there is common function, so I can dynamic generate condition. for example:
public Condition generateCondition(Field<?> field, Object obj, Class<?> type) {
if () {
return DSL.trueCondition();
}
return field.eq(obj, type);
}
I have see this question Is there a way to query by example in Jooq?, it's useful for search single table, but when I need search from multiple table, I don't know how to do...