mybatis-plus lambda条件构造器

mybatis-plus lambda条件构造器

 

mp框架提供了lambda表达式条件构造器支持;

实例:

/**
     * 查找薪水大于3500 名字里有“小”的 员工(通过Lambda表达式)
     * sql: select * from t_employee where salary>3500 and name like '%小%'
     */
    @Test
    public void selectByQueryWrapperWidthLambda(){
        LambdaQueryWrapper<Employee> lambdaQueryWrapper=new QueryWrapper<Employee>().lambda();
        // LambdaQueryWrapper<Employee> lambdaQueryWrapper2=new LambdaQueryWrapper();
        // LambdaQueryWrapper<Employee> lambdaQueryWrapper3=Wrappers.lambdaQuery();
        // queryWrapper.gt("salary",3500).like("name","小");
        lambdaQueryWrapper
                .gt(Employee::getSalary,"3500")
                .like(Employee::getName,"");
        List<Employee> employeeList = employeeMapper.selectList(lambdaQueryWrapper);
        System.out.println(employeeList);
    }
 /**
     * 查找薪水大于3500 名字里有“小”的 员工(通过Lambda表达式) chain
     * sql: select * from t_employee where salary>3500 and name like '%小%'
     */
    @Test
    public void selectByQueryWrapperWidthLambda2(){
        List<Employee> employeeList = new LambdaQueryChainWrapper<Employee>(employeeMapper)
                .gt(Employee::getSalary, "3500")
                .like(Employee::getName, "")
                .list();
        System.out.println(employeeList);
  
    }

 

 

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

作者: java1234_小锋

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

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

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

posted @ 2020-09-15 15:27  java锋哥  阅读(4119)  评论(0编辑  收藏  举报