mybatisPlus条件查询
程序员文章站
2024-03-02 13:13:34
...
mybatisPlus提供了wrapper条件查询的方法,可以实现各种各样的条件查询,下面给出一些常用的条件方法,如需用到其他的条件方法可以到官网中很容易找到;
- eq(“name”, “老王”)—>name = ‘老王’
- ne(“name”, “老王”)—>name <> ‘老王’
- gt(“age”, 18)—>age > 18
- ge(“age”, 18)—>age >= 18
- lt(“age”, 18)—>age < 18
- le(“age”, 18)—>age <= 18
- like(“name”, “王”)—>name like ‘%王%’
- likeLeft(“name”, “王”)—>name like ‘%王’
- isNull(“name”)—>name is null
- in(“age”,{1,2,3})—>age in (1,2,3)
- groupBy(“id”, “name”)—>group by id,name
- orderByAsc(“id”, “name”)—>order by id ASC,name ASC
- orderByDesc(“id”, “name”)—>order by id DESC,name DESC
- 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);
}