更新时间:2023-03-30 来源:黑马程序员 浏览量:
QueryWrapper是MyBatis-Plus框架提供的一个查询构造器,可以用于构建复杂的查询条件,同时具有高度可定制的功能。下面是一些常见的用法和示例代码:
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("name", "张三"); List<User> userList = userMapper.selectList(queryWrapper);
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); queryWrapper.like("name", "张"); List<User> userList = userMapper.selectList(queryWrapper);
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("age", 20).ne("status", "deleted"); List<User> userList = userMapper.selectList(queryWrapper);
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); queryWrapper.orderByAsc("age"); List<User> userList = userMapper.selectList(queryWrapper);
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("age", 20); Page<User> page = new Page<>(1, 10); IPage<User> userPage = userMapper.selectPage(page, queryWrapper); List<User> userList = userPage.getRecords();
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); queryWrapper.inSql("id", "select user_id from user_role where role_id = 1"); List<User> userList = userMapper.selectList(queryWrapper);
以上是一些常见的用法和示例代码,更多用法可以参考MyBatis-Plus的官方文档。