更新時間:2023-03-30 來源:黑馬程序員 瀏覽量:
QueryWrapper是MyBatis-Plus框架提供的一個查詢構(gòu)造器,可以用于構(gòu)建復雜的查詢條件,同時具有高度可定制的功能。下面是一些常見的用法和示例代碼:
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的官方文檔。