欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mybatisPlus条件查询

程序员文章站 2024-03-02 13:13:34
...

mybatisPlus提供了wrapper条件查询的方法,可以实现各种各样的条件查询,下面给出一些常用的条件方法,如需用到其他的条件方法可以到官网中很容易找到;

  1. eq(“name”, “老王”)—>name = ‘老王’
  2. ne(“name”, “老王”)—>name <> ‘老王’
  3. gt(“age”, 18)—>age > 18
  4. ge(“age”, 18)—>age >= 18
  5. lt(“age”, 18)—>age < 18
  6. le(“age”, 18)—>age <= 18
  7. like(“name”, “王”)—>name like ‘%王%’
  8. likeLeft(“name”, “王”)—>name like ‘%王’
  9. isNull(“name”)—>name is null
  10. in(“age”,{1,2,3})—>age in (1,2,3)
  11. groupBy(“id”, “name”)—>group by id,name
  12. orderByAsc(“id”, “name”)—>order by id ASC,name ASC
  13. orderByDesc(“id”, “name”)—>order by id DESC,name DESC
  14. and(i -> i.eq(“name”, “李白”).ne(“status”, “活着”))—>and (name = ‘李白’ and status <> ‘活着’)

使用方法

@Test
void testDeleted(){
    User user=userMapper.selectById(1);
    QueryWrapper wrapper=  new QueryWrapper<User>();
    wrapper.eq("id",1);
    List<User> list=userMapper.selectList(wrapper);
    list.forEach(System.out::println);
}
相关标签: SSM mybatis