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