mybatisplus中按照条件查询的三种方式,常用的是lambda查询,当进行测试查询的时候,可以将日志中冗余的文件关闭,在application.yml中设置就可以了,还需要设置一个空的logback.xml

发布时间 2023-09-10 18:50:46作者: 努力是一种常态

2023-09-10

目录结构

 logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
</configuration>

application.yml

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/db01?serverTimezone=UTC
    username: root
    password: 123456
    type: com.alibaba.druid.pool.DruidDataSource
  main:
    banner-mode: off
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  global-config:
    banner: false

TestDeptDao

@Test
    public void selectConditionOne(){
        QueryWrapper<Dept> qw = new QueryWrapper<>();
        qw.lt("id", 20);
        List<Dept> depts = deptDao.selectList(qw);
        System.out.println("depts = " + depts);
    }

    @Test
    public void selectConditionTwo(){
        QueryWrapper<Dept> qw = new QueryWrapper<>();
        qw.lambda().ge(Dept::getId,20);
        List<Dept> depts = deptDao.selectList(qw);
        System.out.println("depts = " + depts);
    }

    @Test
    public void selectConditionThree(){
        LambdaQueryWrapper<Dept> lqw = new LambdaQueryWrapper<>();
        lqw.ge(Dept::getId,10);
        List<Dept> depts = deptDao.selectList(lqw);
        System.out.println("depts = " + depts);
    }

    @Test
    public void selectConditionMultOne(){
        LambdaQueryWrapper<Dept> lqw = new LambdaQueryWrapper<>();
        lqw.ge(Dept::getId,10);
        lqw.le(Dept::getId,30);
        List<Dept> depts = deptDao.selectList(lqw);
        System.out.println("depts = " + depts);
    }

    @Test
    public void selectConditionMultTwo(){
        LambdaQueryWrapper<Dept> lqw = new LambdaQueryWrapper<>();
        lqw.ge(Dept::getId,40).or().le(Dept::getId,10);
        List<Dept> depts = deptDao.selectList(lqw);
        System.out.println("depts = " + depts);
    }