-
Notifications
You must be signed in to change notification settings - Fork 212
Add the Ability to Transform Condition Values After the "when()" Check #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@pky920216344 Wow - this is a great idea - thanks! I would implement it more like this: public IsLike<T> then(UnaryOperator<T> transformer) {
return shouldRender() ? new IsLike<>(() -> transformer.apply(value())) : this;
} Then we could write code like this: SelectStatementProvider selectStatement = select(id, firstName, lastName)
.from(person)
.where(firstName, isLike(fName).when(Objects::nonNull).then(s -> "%" + s + "%"))
.and(lastName, isLike(lName).when(Objects::nonNull).then(s -> "%" + s + "%"))
.build()
.render(RenderingStrategy.MYBATIS3); What do you think? |
If you write a little utility class like this: public class SearchUtils {
public static String addWildcards(String s) {
return "%" + s + "%";
}
} Then you can write code like this: SelectStatementProvider selectStatement = select(id, firstName, lastName)
.from(person)
.where(firstName, isLike(fName).when(Objects::nonNull).then(SearchUtils::addWildcards))
.and(lastName, isLike(lName).when(Objects::nonNull).then(SearchUtils::addWildcards))
.build()
.render(RenderingStrategy.MYBATIS3); I think this qualifies as beautiful 😄 |
@jeffgbutler better than me hope I can use it as soon as possible 😀 |
I’ll add this and do a release very soon. |
@pky920216344 this is released and available now in version 1.1.2 |
@jeffgbutler Thank you 😄 |
example:


like this, parameter is null, but "%"+parameter+"%" is not null
When do fuzzy query operation, i must coding:
if(null!=parameter){
xxx.and(column, ()-> "%"+parameter+"%");
}
it's not beautiful
The text was updated successfully, but these errors were encountered: