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

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);
    }
复制代码

 

posted @   努力是一种常态  阅读(321)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
历史上的今天:
2022-09-10 Mysql第8天
2022-09-10 闭包第2天
点击右上角即可分享
微信分享提示