mybatis-plus条件构造器简介

mybatis-plus条件构造器简介

 

mybatis-plus提供了AbstractWrapper抽象类,提供了很多sql语法支持的方法,比如模糊查询,比较,区间,分组查询,排序,判断空,子查询等等,方便我们用面向对象的方式去实现sql语句;

1.jpg

 

AbstractWrapper有两个常用的实现类,分别是QueryWrapper和UpdateWrapper,我们以后就用这两个实现类;

 

下面搞两个实例来体验下QueryWrapper条件构造器:

/**
 * 查找薪水大于3500 名字里有“小”的 员工
 * sql: select * from t_employee where salary>3500 and name like '%小%'
 */
@Test
public void selectByQueryWrapper(){
    QueryWrapper<Employee> queryWrapper=new QueryWrapper();
    // QueryWrapper<Employee> queryWrapper2=Wrappers.<Employee>query();
    queryWrapper.gt("salary",3500).like("name","");
    List<Employee> employeeList = employeeMapper.selectList(queryWrapper);
    System.out.println(employeeList);
}
 
/**
 * 查找薪水范围【3500,5000】,名字里有“小”以及email不为空 的员工
 * sql: select * from t_employee where between 3500 and 5000 and name like '%小%' and email is not null
 */
@Test
public void selectByQueryWrapper2(){
    QueryWrapper<Employee> queryWrapper=new QueryWrapper();
    // QueryWrapper<Employee> queryWrapper2=Wrappers.<Employee>query();
    queryWrapper.like("name","").between("salary",3500,5000).isNotNull("email");
    List<Employee> employeeList = employeeMapper.selectList(queryWrapper);
    System.out.println(employeeList);
}

 

 

------------------------------------------------------------------------------------------------------------------------------

作者: java1234_小锋

出处:https://www.cnblogs.com/java688/p/13563938.html

版权:本站使用「CC BY 4.0」创作共享协议,转载请在文章明显位置注明作者及出处。

------------------------------------------------------------------------------------------------------------------------------



posted @ 2020-08-26 14:42  java锋哥  阅读(3178)  评论(0编辑  收藏  举报