问答详情
源自:3-6 select不列出全部字段

主键id 不能使用 第2中方式 吗 ?

info -> info.getColumn().equals("id");

提问者:慕丝1577759 2019-07-17 15:57

个回答

  • 老猿
    2019-07-18 13:25:08

    可以的呀,同学。可以这样写,例如:query.select(User.class, info->info.getColumn().equals("id"));

  • 忙碌的程序猿
    2020-10-01 14:36:36

    query.select(User.class, !info->info.getColumn().equals("id"));

    这样写排除不了id,结果集id还是会显示出来。

    @Test
    public void selectPartOfColumns(){
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.like("name","雨").gt("age",20)
                .select(User.class,c -> !c.getColumn().equals("id")
                );
        List<User> list = userMapper.selectList(qw);
        list.forEach(System.out::println);
    }


    DEBUG==>  Preparing: SELECT id,create_time,name,manager_id,email,age FROM user WHERE (name LIKE ? AND age > ?) 

    DEBUG==> Parameters: %雨%(String), 20(Integer)

    TRACE<==    Columns: id, create_time, name, manager_id, email, age

    TRACE<==        Row: 1094590409767661570, 2019-01-14 09:15:15, 张雨琪, 1088248166370832385, zjq@baomidou.com, 31

    TRACE<==        Row: 1094592041087729666, 2019-01-14 09:48:16, 刘红雨, 1088248166370832385, lhm@baomidou.com, 32

    DEBUG<==      Total: 2

    User(id=1094590409767661570, name=张雨琪, age=31, email=zjq@baomidou.com, managerId=1088248166370832385, createTime=2019-01-14T09:15:15)

    User(id=1094592041087729666, name=刘红雨, age=32, email=lhm@baomidou.com, managerId=1088248166370832385, createTime=2019-01-14T09:48:16)