在Fluent Mybatis中,可以使用where()方法来添加where条件,可以通过andor等方法来组合多个条件。如果需要改变条件的优先级,可以使用where().andNested()where().orNested()方法来添加括号。

下面是一个示例:

import cn.org.atool.fluent.mybatis.If;
import static cn.org.atool.fluent.mybatis.mapper.FluentConst.*;

public class UserMapper extends FluentMapper<UserEntity> {
    public static final UserMapper Mapper = new UserMapper();

    public UserMapper() {
        this.select("id", "username", "age")
            .from(userTable)
            .where()
                .and(UserEntity::getAge, If::gt, 18)
                .andNested(nested -> nested
                    .or(UserEntity::getUsername, If::like, "%admin%")
                    .or(UserEntity::getUsername, If::like, "%user%")
                )
                .end()
            .end()
            .orderBy.asc(UserEntity::getAge)
            .limit(10)
            .end();
    }
}

在上述示例中,使用andNested()方法将两个or条件括起来,改变了它们的优先级

fluent-mybatis的where条件怎么添加括号改变优先级

原文地址: http://www.cveoy.top/t/topic/isgR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录