java1234开源博客系统
博客信息

mybatis-plus lambda条件构造器

0
发布时间:『 2020-09-04 12:48』  博客类别:mybatis-plus  阅读(134)

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微信公众号
博主信息
Java1234_小锋
(知识改变命运,技术改变世界)
Powered by Java1234 V3.0 Copyright © 2012-2016 Java知识分享网 版权所有