MybatisPlus--QueryWrapper

article/2025/10/22 20:40:59

QueryWrapper

wrapper介绍
在这里插入图片描述

  • Wrapper : 条件构造抽象类,最顶端父类
    • AbstractWrapper : 用于查询条件封装,生成 sql 的 where 条件
      • QueryWrapper : Entity 对象封装操作类,不是用lambda语法
      • UpdateWrapper : Update 条件封装,用于Entity对象更新操作
      • AbstractLambdaWrapper : Lambda 语法使用 Wrapper统一处理解析 lambda 获取 column。
        • LambdaQueryWrapper :看名称也能明白就是用于Lambda语法使用的查询Wrapper
        • LambdaUpdateWrapper : Lambda 更新封装Wrapper
  • 如果想进行复杂条件查询,那么需要使用条件构造器 Wapper,涉及到如下方法
    在这里插入图片描述
  • 拼凑条件相关关键字
    在这里插入图片描述
    在这里插入图片描述
    条件查询
  • 基本多条件查询
    @Testpublic void testQueryWrapper(){// todo 拼凑条件QueryWrapper queryWrapper = new QueryWrapper();// todo 等值查询queryWrapper.eq("password","1234");// todo 模糊查询queryWrapper.like("cname","o");// todo 范围查询 大于等于queryWrapper.ge("money",800);// todo 范围查询 小于等于queryWrapper.le("money",1000);//todo 条件查询List<Customer> list = customerMapper.selectList(queryWrapper);list.forEach(System.out::println);}
  • 条件判断
   @Testpublic void findCondition2() {Customer customer = new Customer();customer.setPassword("777");customer.setCname("888");customer.setIdList(Arrays.asList(2,3,4));customer.setCid(3);//条件查询QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();// 1) 等值查询queryWrapper.eq( customer.getPassword()!=null ,"password", customer.getPassword());// 2) 模糊查询queryWrapper.like(customer.getCname() != null , "cname",customer.getCname());// 3) in语句queryWrapper.in(customer.getIdList() != null , "cid",customer.getIdList());// 4) 大于等于queryWrapper.ge(customer.getCid() != null , "cid" , customer.getCid());//查询List<Customer> list = customerMapper.selectList(queryWrapper);//list.forEach(customer-> System.out.println(customer));list.forEach(System.out::println);}
  • 条件更新
  @Testpublic void testUpdateByQueryMapper(){//1.todo 更新数据Customer customer = new Customer();customer.setVersion(1);//2.todo 更新条件UpdateWrapper<Customer> updateWrapper = new UpdateWrapper<>();updateWrapper.in("cid",1,2,3);//3.todo 更新int update = customerMapper.update(customer, updateWrapper);System.out.println(update);}

分页

主体插件: MybatisPlusInterceptor,该插件内部插件集:

  • 分页插件: PaginationInnerInterceptor
  • 多租户插件: TenantLineInnerInterceptor
  • 动态表名插件: DynamicTableNameInnerInterceptor
  • 乐观锁插件: OptimisticLockerInnerInterceptor
  • sql性能规范插件: IllegalSQLInnerInterceptor
  • 防止全表更新与删除插件: BlockAttackInnerInterceptor
    配置类
    在这里插入图片描述
package com.czxy.mp.config;import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class MybatisPlusConfig {/*** 配置插件* @return*/@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor(){MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();// 分页插件mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));return mybatisPlusInterceptor;}/*** 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)* @return*/@Beanpublic ConfigurationCustomizer configurationCustomizer() {return configuration -> configuration.setUseDeprecatedExecutor(false);}
}

分页

@Testpublic void testPage(){// 分页数据int pageNum = 1;int pageSize = 3;Page<Customer> page = new Page<>(pageNum , pageSize);page.setSearchCount(true);// 查询customerMapper.selectPage(page, null);// 分页数据System.err.println("当前页码:" + page.getCurrent());System.err.println("每页显示记录数:" + page.getSize());System.err.println("总页数:" + page.getPages());System.err.println("总记录数:" + page.getTotal());System.err.println("是否有下一页:" + page.hasNext());System.err.println("是否有上一页:" + page.hasPrevious());// 分页数据列表page.getRecords().forEach(System.err::println);}

常见注解

表名注解:@TableName
在这里插入图片描述
主键注解:@TableId
在这里插入图片描述
字段注解(非主键) : @TableField
在这里插入图片描述
常见配置

mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl  #输出日志map-underscore-to-camel-case: true  #驼峰命名global-config:db-config:id-type: auto  #全局配置,id自动增强table-prefix: tmp_ #表名前缀type-aliases-package: com.czxy.mp.domain #别名包扫描路径mapper-locations: classpath*:/mapper/**/*.xml #映射文件位置

http://chatgpt.dhexx.cn/article/9JjhhPBe.shtml

相关文章

Gradle基础:9:wrapper的使用

Gradle Wrapper是gradle建议的使用方式&#xff0c;这篇文章将会结合具体的例子来说明一下如何使用。 Gradle Wrapper Gradle Wrapper实际上就是一个脚本&#xff0c;使用它可以下载和使用指定版本的gradle&#xff0c;根据需要进行在使用之前进行下载&#xff0c;有效避免本…

spring boot之maven-wrapper

Spring Boot有很多功能特性值得借鉴和学习&#xff0c;很多玩Spring Boot的人知道不需要安装Tomcat很方便&#xff0c;其实并没有发现Maven也是不需要提前安装。它这样做的好处在于解决了开发环境maven版本不一致导致的各种问题&#xff0c;spring boot中集成了maven-wrapper的…

dubbo之SPI Wrapper分析

写在前面 本文需要dubbo SPI的简单基础知识&#xff0c;对dubbo SPI不了解的朋友可以参考dubbo之SPI分析 。 源码&#xff01;&#xff01;&#xff01;。 在dubbo之SPI分析 文章中我们分析了SPI机制&#xff0c;其中有种SPI是一个Wrapper类的情况&#xff0c;本文一起来看下Wr…

MyBatis与QueryWrapper

目录 一、MyBatis标签 1.2 if标签 1.2 foreach标签 1.3 sql标签 1.4 where标签 1.5SQL片段的使用 二、条件构造器 2.1QueryWrapper 2.1.1查询 2.1.2 查询列2 2.1.2 删除 2.1.3子查询 2.1.4组装查询条件 2.1.5组装排序条件 2.1.6组装删除条件 2.1.7条件的优先级 2.1.8 子…

QueryWrapper常用方法

QueryWrapper常用方法 MybatisPlus 使用QueryWrapper测试用例 一、ge、gt、le、lt、isNull、isNotNull Test public void testQuery() { QueryWrapper<User> queryWrapper new QueryWrapper<>();queryWrapper.isNull("name").ge("age", 12)…

java service wrapper 中文_Java Service Wrapper实践

很久前就使用JAVA写了一个后台服务器,基于MINA框架的。并且一直部署运行于服务器中,当然有一个黑框框。 就正常运行而言,此种运行方式没有任何问题。 但是就这运行期间出现的一些问题: 1,服务器问题重启后,每次都要登录远程将服务器打开,即使我已经配置了开机自启动,但…

Gradle Wrapper 详解

Gradle Wrapper 详解 我们介绍了 Android 项目的目录及 Gradle 配置&#xff0c;我们提到有个目录是/gradle/wrapper。今天这篇文章我们来学习 Gradle Wrapper。通过这篇文章我们将了解什么是 Gradle Wrapper&#xff1f;为什么需要用 Gradle Wrapper&#xff1f;以及 Gradle …

wrapper java 64_Wrapper配置详解及高级应用

将一个简单的程度如HelloWorld 的应用包装秤Wrapper 服务并不复杂&#xff0c;甚至可以认为非常简单。但是实际项目应用过程中我们的程序一般较庞大&#xff0c;运行环境也较复杂。 通过Wrapper 配置文件的分析与配置进一步了解构建Wrapper 服务需要注意的关键点及重要部分。 首…

RDP Wrapper

说到要在非Windows Server版本上实现多用户远程桌面连接 &#xff0c;我们都知道一个大名鼎鼎的软件RDP Wrapper Library&#xff0c;它是开源的&#xff0c;所有秘密作者都没有保留&#xff0c;所有问题全部在GitHub上面写的清清楚楚&#xff0c;在这里感谢这些伟大的人&#…

wrapper后台启动java程序

文章目录 1&#xff0c;下载wrapper2&#xff0c;使用wrapper后台启动java程序2.1&#xff0c;编写java样例程序2.2&#xff0c;配置wrapper2.3&#xff0c;拷贝启动脚本2.4&#xff0c;启动服务 1&#xff0c;下载wrapper 下载地址&#xff1a;https://wrapper.tanukisoftwar…

Java常用类-包装类(Wrapper)简单介绍

目录 前言1、包装类(Wrapper) 前言 本文主要介绍java中的包装类 1、包装类(Wrapper) Java是面向对象的编程语言&#xff0c;但它也包含了8种基本数据类型&#xff0c;这8种基本数据类型不支持面向对象的编程机制&#xff0c;基本数据类型的数据也不具备“对象”的特性&#…

强大的wrapper

最近在看大数据和容器相关的东西&#xff0c;发现有一个模式被反复使用到&#xff0c;关键是被用的很恰当且优雅&#xff0c;并能在这些关键技术中都发挥着至关重要的核心作用。我想你已经猜到了&#xff0c;他就是Eminem——强大的rapper——哦&#xff0c;不对&#xff0c;是…

mybatis-plus中wrapper的用法(详细)

用到了wrapper&#xff0c;ge、le、ne、eq等的用法&#xff0c;及多表查询自写sql整理资料记录一下&#xff0c;以备后续复习。 目录------------&#xff08;可点击相应目录直接跳转&#xff09; 一、条件构造器关系介绍 条件构造器关系介绍 &#xff1a; wapper介绍 &…

锚点(anchorPoint)

转载请说明出处&#xff0c;谢谢。 原文出处&#xff1a;点击打开链接 今天研究了一下关于layer的anchorPoint问题。 附图&#xff1a; 原文出处&#xff1a;点击打开链接 位置坐标 position&#xff0b;anchorPoint&#xff08;左下角0,0原点坐标系&#xff09;。 要确…

cocos2d-x中的锚点(AnchorPoint)理解

锚点的定义 锚点是指节点在进行形状变换、位置变动时依据的基准点。可以想象为钉在墙上用于固定纸张的小图钉&#xff0c;或者公告栏上用于固定纸张用的围棋状的小磁粒。当对某个节点调用setPosition时&#xff0c;cocos2d-x即会将其锚点移动到相应位置&#xff1b;当对节点进行…

cocos2d-x3.2总结(一)Position和AnchorPoint的关系

当cocos2d-x引擎需要绘图时&#xff0c;就需要Position和AnchorPoint等属性。例如&#xff1a;在创建一个Sprite时&#xff0c;要设置Sprite的Position&#xff0c;而我们常常没有设置AnchorPoint&#xff0c;这是因为精灵的AnchorPoint默认值为&#xff08;0.5,0.5&#xff09…

Anchor3

这里介绍如何修改 Anchor 的尺寸来提高小目标的检测效果,算法tricks优化小目标检测 修改 Anchor 尺寸 在实际的应用场景中&#xff0c;我们按照 MS COCO 标准中把大小不大于 32x32 或者占原始图片比率不足 0.01 的目标物体定义为一个小目标物体。 在使用 Anchor 的检测算法&…

ios-anchorPoint、position理解

anchorPoint(锚点)是layer的一个属性&#xff0c;下面我们来看看其对view的影响&#xff0c;本文主要通过图片方式展现&#xff1a; 锚点用单位坐标来描述也就是图层的相对坐标。在苹果文档中说明左下是(0,0),右上是&#xff08;1&#xff0c;1&#xff09;&#xff0c;mac系统…

Anderson‘s pointer analysis

本文是垃圾文章&#xff0c;请直接学习其它资料 南京大学《软件分析》课程08&#xff08;Pointer Analysis&#xff09;https://www.cs.cmu.edu/~aldrich/courses/15-819O-13sp/resources/pointer.pdf 指针分析 指针分析是一类特殊的数据流问题&#xff0c;它是其它静态程序分析…

iOS围绕某点缩放或旋转的AnchorPoint的设定

经常会遇到需求&#xff0c;要求手势的缩放或者旋转操作&#xff0c;要求动作变化围绕某一个特定点&#xff0c;或者是两指的中心点&#xff0c;或者是某一个点。 这个问题首先要清晰的知道&#xff0c;iOS各个view的层次关系。特别是&#xff0c;要清除的知道&#xff0c;当前…