LambdaQueryChainWrapper对象后面可以直接跟方法名:

Activity one = new LambdaQueryChainWrapper<>(activityMapper)
                .eq(Activity::getId, activityId)
                .select(Activity::getTitle)
                .one();
  • 1.
  • 2.
  • 3.
  • 4.

上面直接调用了one()查询方法,其他list()、count()等方法也是可以的,等价于:

Activity one = activityMapper.selectOne(new LambdaQueryWrapper<Activity>()
            .eq(Activity::getId, activityId)
            .select(Activity::getTitle)
    );
  • 1.
  • 2.
  • 3.
  • 4.

再看mybatisPlus的代码:

default T one() {
    return this.execute((mapper) -> {
        return mapper.selectOne(this.getWrapper());
    });
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

也就是说通过LambdaQueryChainWrapper对象调用one()方法,其实内层其实执行了mapper.selectOne(Wrapper<T> wrapper)方法,使用LambdaQueryWrapper代码会更直接一些。