当前位置:   article > 正文

QueryWrapper常见用法都有哪些?_querywrapper querywrapper = new querywrapper(); qu

querywrapper querywrapper = new querywrapper(); querywrapper.eq("usr_name",

QueryWrapper是MyBatis-Plus框架提供的一个查询构造器,可以用于构建复杂的查询条件,同时具有高度可定制的功能。下面是一些常见的用法和示例代码:

1680140076170_QueryWrapper常见用法都有哪些.jpg

       1.等值查询

  1. QueryWrapper<User> queryWrapper = new QueryWrapper<>();
  2. queryWrapper.eq("name", "张三");
  3. List<User> userList = userMapper.selectList(queryWrapper);

  2.模糊查询

  1. QueryWrapper<User> queryWrapper = new QueryWrapper<>();
  2. queryWrapper.like("name", "张");
  3. List<User> userList = userMapper.selectList(queryWrapper);

  3.多条件查询

  1. QueryWrapper<User> queryWrapper = new QueryWrapper<>();
  2. queryWrapper.eq("age", 20).ne("status", "deleted");
  3. List<User> userList = userMapper.selectList(queryWrapper);

     4.排序查询

  1. QueryWrapper<User> queryWrapper = new QueryWrapper<>();
  2. queryWrapper.orderByAsc("age");
  3. List<User> userList = userMapper.selectList(queryWrapper);

  5.分页查询

  1. QueryWrapper<User> queryWrapper = new QueryWrapper<>();
  2. queryWrapper.eq("age", 20);
  3. Page<User> page = new Page<>(1, 10);
  4. IPage<User> userPage = userMapper.selectPage(page, queryWrapper);
  5. List<User> userList = userPage.getRecords();

  6.子查询

  1. QueryWrapper<User> queryWrapper = new QueryWrapper<>();
  2. queryWrapper.inSql("id", "select user_id from user_role where role_id = 1");
  3. List<User> userList = userMapper.selectList(queryWrapper);

  以上是一些常见的用法和示例代码,更多用法可以参考MyBatis-Plus的官方文档。

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号