目录

一、Wrapper介绍

二、QueryWrapper的方法

三、目录结构

(1)目录

1、实体类

2、Mapper接口层

3、AnimalServiceImpl服务实现层

4、IAnimalService服务类

5、application.yml配置

(2)数据库

四、实例

(1)eq、ne

(2)gt、ge、lt、le

(3)between、notbetween

(4)like、notLike、likeLeft、likeRight

(5)isNull、isNotNull

(6)in、notIn

(7)inSql、notInSql

(8)or、and

(9)exists、notExists

(10)orderByAsc、orderByDesc


一、Wrapper介绍

在Mybatis-Plus(MP)中,简单的查询可以使用MP已经封装好的API来实现,但复杂的查询语句可以通过MP提供的Wrapper来进行封装。

Wrapper继承体系

Wrapper:条件构造抽象类,最顶端父类.

  • AbstractWrapper:用于查询条件封装,生成sql的where条件
  • QueryWrapper:Entity对象封装操作类,不是lambda语法
  • UpdateWrapper:Update条件封装,用于Entity对象更新操作
  • AbstractLambdaWrapper:Lambda语法使用Wrapper统一处理解析lambda获取column
  • LambdaQueryWrapper:用于Lambda语法使用的查询Wrapper
  • LambdaUpdateWrapper:Lambda更新封装Wrapper

二、QueryWrapper的方法

三、目录结构

(1)目录

1、实体类

@TableName("animal")    --->  关联的表名

@Data---->引入Lombok插件即可使用

@DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss")--->日期格式转换.

@DateTimeFormat注解加不加都可以,因为使用的是String类型.

package com.wrapper.entity;import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;/*** 动物实体类*/@TableName("animal")
@EqualsAndHashCode(callSuper = false)
@Data
public class Animal {/*** 动物名称*/private String name;/*** 年龄*/private int age;/*** 动物别名*/private String alias;/*** 动物描述*/private String description;/*** 动物信息入机时间*/@DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss")private String inputtime;/*** 更新时间*/@DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss")private String updatetime;}

2、Mapper接口层

package com.wrapper.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wrapper.entity.Animal;
import org.apache.ibatis.annotations.Mapper;/*** 接口*/
@Mapper
public interface AnimalMapper extends BaseMapper<Animal> {
}

3、AnimalServiceImpl服务实现层

package com.wrapper.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wrapper.entity.Animal;
import com.wrapper.mapper.AnimalMapper;
import com.wrapper.service.IAnimalService;
import org.springframework.stereotype.Service;/*** 服务实现层*/
@Service
public class AnimalServiceImpl extends ServiceImpl<AnimalMapper, Animal> implements IAnimalService {
}

4、IAnimalService服务类

package com.wrapper.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.wrapper.entity.Animal;/*** 服务类*/
public interface IAnimalService extends IService<Animal> {
}

5、application.yml配置

spring:datasource:username: rootpassword: 123456#?serverTimezone=UTC解决时区的报错url: jdbc:mysql://localhost:3306/wapper_test_20211201?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8driver-class-name: com.mysql.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSource

6、pom.xml配置

这里引用了thymeleaf和freemarker模板引擎依赖.去掉也可以.项目中并没有用到.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.wrapper</groupId><artifactId>wrapper</artifactId><version>0.0.1-SNAPSHOT</version><name>wrapper</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><spring-boot.version>2.3.7.RELEASE</spring-boot.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.2</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.22</version><scope>compile</scope></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.3.7.RELEASE</version><configuration><mainClass>com.wrapper.WrapperApplication</mainClass></configuration><executions><execution><id>repackage</id><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>

(2)数据库

CREATE TABLE `animal` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '自增主键',`name` varchar(20) NOT NULL COMMENT '动物名称',`age` int DEFAULT NULL COMMENT '年龄',`alias` varchar(40) NOT NULL COMMENT '动物别名',`description` varchar(300) DEFAULT '' COMMENT '动物描述',`inputtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '动物信息入机时间',`updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '动物信息更新时间',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

四、实例

(1)eq、ne

eq:等于

    @Testvoid contextEq() {QueryWrapper<Animal> queryWrapper = new QueryWrapper<>();//eq:等于//查询name等于狮子的数据.QueryWrapper<Animal> eq = queryWrapper.eq("name", "狮子");Animal one = animalService.getOne(eq);System.out.println(one);}
Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09)

ne:不等于

 @Testvoid contextNe() {QueryWrapper<Animal> queryWrapper = new QueryWrapper<>();//ne:不等于//查询name不等于蓝猫的数据QueryWrapper<Animal> ne = queryWrapper.ne("name", "蓝猫");//name不等于蓝猫的数据有多条,所以使用listList<Animal> list = animalService.list(ne);System.out.println(list);}
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02), Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=孔雀, age=3, alias=白孔雀, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09), Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12), Animal(name=西伯利亚雪橇犬, age=6, alias=二哈, description=富足家庭中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:14), Animal(name=大熊猫, age=8, alias=国宝, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:19)]

(2)gt、ge、lt、le

gt:大于,ge:大于等

@Testvoid contextGt() {QueryWrapper<Animal> queryWrapper = new QueryWrapper<>();//gt:大于  查询年龄age大于4的数据QueryWrapper<Animal> gt = queryWrapper.gt("age", 5);List<Animal> list1 = animalService.list(gt);System.out.println(list1);System.out.println("===============================");//ge:大于等于  查询年龄大于等于5的数据QueryWrapper<Animal> ge = queryWrapper.ge("age", 6);List<Animal> list2 = animalService.list(ge);System.out.println(list2);}
[Animal(name=西伯利亚雪橇犬, age=6, alias=二哈, description=富足家庭中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:14), Animal(name=蓝猫, age=7, alias=猫, description=家养, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:16), Animal(name=大熊猫, age=8, alias=国宝, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:19)]
===============================
[Animal(name=西伯利亚雪橇犬, age=6, alias=二哈, description=富足家庭中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:14), Animal(name=蓝猫, age=7, alias=猫, description=家养, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:16), Animal(name=大熊猫, age=8, alias=国宝, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:19)]

lt:小于,le:小于等于

@Testvoid contextLt() {//第一种写法  lt:小于  查询年龄小于6的数据QueryWrapper<Animal> queryWrapper = new QueryWrapper<>();QueryWrapper<Animal> lt = queryWrapper.lt("age", 6);List<Animal> list3 = animalService.list(lt);System.out.println(list3);//第二种写法List<Animal> list4 = animalService.list(new LambdaQueryWrapper<Animal>().lt(Animal::getAge, 6));System.out.println(list4);System.out.println("=======================");//第一种写法  le:小于等于   查询年龄小于等于5的数据QueryWrapper<Animal> queryWrapper1 = new QueryWrapper<>();QueryWrapper<Animal> le = queryWrapper1.le("age",5);List<Animal> list5 = animalService.list(le);System.out.println(list5);//第二种写法List<Animal> list6 = animalService.list(new LambdaQueryWrapper<Animal>().le(Animal::getAge,5));System.out.println(list6);}
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02), Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=孔雀, age=3, alias=白孔雀, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09), Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12)]
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02), Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=孔雀, age=3, alias=白孔雀, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09), Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12)]
=======================
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02), Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=孔雀, age=3, alias=白孔雀, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09), Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12)]
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02), Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=孔雀, age=3, alias=白孔雀, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09), Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12)]

(3)between、notbetween

between:在值1和值2之间,notbetween:不在值1和值2之间

    @Testvoid contextBetween(){//between:在值1和值2之间.   查询年龄为5到7之间的数据List<Animal> list7 = animalService.list(new LambdaQueryWrapper<Animal>().between(Animal::getAge,5,7));System.out.println(list7);System.out.println("================");//notbetween:不在值1和值2之间List<Animal> list8 = animalService.list(new LambdaQueryWrapper<Animal>().notBetween(Animal::getAge,2,8));System.out.println(list8);}
[Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12), Animal(name=西伯利亚雪橇犬, age=6, alias=二哈, description=富足家庭中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:14), Animal(name=蓝猫, age=7, alias=猫, description=家养, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:16)]
================
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02)]

(4)like、notLike、likeLeft、likeRight

like:’%值%’,notLike:’%值%’

    @Testvoid contextLike(){//like:%值%  sql中的模糊查询  查询名字中带有犬的数据List<Animal> list9 = animalService.list(new LambdaQueryWrapper<Animal>().like(Animal::getName,"犬"));System.out.println(list9);System.out.println("=============================");//notLike:%值%  查询名字不带有猫的数据List<Animal> list10 = animalService.list(new LambdaQueryWrapper<Animal>().notLike(Animal::getName,"猫"));System.out.println(list10);}
[Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12), Animal(name=西伯利亚雪橇犬, age=6, alias=二哈, description=富足家庭中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:14)]
=============================
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02), Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=孔雀, age=3, alias=白孔雀, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09), Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12), Animal(name=西伯利亚雪橇犬, age=6, alias=二哈, description=富足家庭中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:14)]

likeLeft:’%值’,likeRight:'值%'

    @Testvoid contextLeftRight(){//likeLeft:%值  左边数据模糊,右边为"虎".  查询name(动物名称)中最后一个为"虎"的数据List<Animal> list11 = animalService.list(new LambdaQueryWrapper<Animal>().likeLeft(Animal::getName,"虎"));System.out.println(list11);System.out.println("===========================");//likeRight:值%  左边为"大",右边数据模糊.  查询名字第一个为"大"的数据List<Animal> list12 = animalService.list(new LambdaQueryWrapper<Animal>().likeRight(Animal::getName,"大"));System.out.println(list12);}
[Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27)]
===========================
[Animal(name=大熊猫, age=8, alias=国宝, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:19)]

(5)isNull、isNotNull

isNull:字段IS NULL(空),isNotNull:字段IS NOT NULL(不为空)

    @Testvoid contextNull(){//isNull:为空  查询alias(动物别名)为空的数据List<Animal> list13 = animalService.list(new LambdaQueryWrapper<Animal>().isNull(Animal::getAlias));System.out.println(list13);System.out.println("=============================");//isNotNull:不为空  查询alias(动物别名)不为空的数据List<Animal> list14 = animalService.list(new LambdaQueryWrapper<Animal>().isNotNull(Animal::getAlias));System.out.println(list14);}
[]
=============================
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02), Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=孔雀, age=3, alias=白孔雀, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09), Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12), Animal(name=西伯利亚雪橇犬, age=6, alias=二哈, description=富足家庭中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:14), Animal(name=蓝猫, age=7, alias=猫, description=家养, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:16), Animal(name=大熊猫, age=8, alias=国宝, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:19)]

(6)in、notIn

in:指定查询的值,notIn:不介于指定的值;in:字段 IN (v0, v1, …),notIn:字段 NOT IN (value.get(0), value.get(1), …)

    @Testvoid contextIn(){//in:指定查询的值  查询age(年龄)为3,4的数据List<Animal> list15 = animalService.list(new LambdaQueryWrapper<Animal>().in(Animal::getAge,3,4));System.out.println(list15);System.out.println("===========================");//notNot:不介于指定的值  查询age(年龄)不为1,2,3,4,5,6的数据List<Animal> list16 = animalService.list(new LambdaQueryWrapper<Animal>().notIn(Animal::getAge,1,2,3,4,5,6));System.out.println(list16);}
[Animal(name=孔雀, age=3, alias=白孔雀, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09)]
===========================
[Animal(name=蓝猫, age=7, alias=猫, description=家养, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:16), Animal(name=大熊猫, age=8, alias=国宝, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:19)]

(7)inSql、notInSql

inSql:字段 IN ( sql语句 ),notInSql:字段 NOT IN ( sql语句 )

    @Testvoid contextInSql(){//inSql:字段In (sql语句)  通过name查询age < 2 的数据List<Animal> list17 = animalService.list(new LambdaQueryWrapper<Animal>().inSql(Animal::getName,"select name from animal where age < 2"));System.out.println(list17);System.out.println("===========================");//notInSql:字段notIn  (sql语句)  通过那么查询age > 7 的数据List<Animal> list18 = animalService.list(new LambdaQueryWrapper<Animal>().notInSql(Animal::getName,"select name from animal where age < 7"));System.out.println(list18);}
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02)]
===========================
[Animal(name=蓝猫, age=7, alias=猫, description=家养, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:16), Animal(name=大熊猫, age=8, alias=国宝, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:19)]

(8)or、and

or:拼接OR,AND嵌套

注意事项:

主动调用or表示紧接着下一个方法不是用and连接!(不调用or则默认为使用and连接)

    @Testvoid contextOrAnd(){//or:或  查询name(动物名称)等于狮子或者age(年龄)小于等于2的数据List<Animal> list19 = animalService.list(new LambdaQueryWrapper<Animal>().eq(Animal::getName,"狮子").or().le(Animal::getAge,2));System.out.println(list19);System.out.println("=======================");//and:并且  查询anme(动物名称)最后一个为"犬"并且age(年龄)大于5的数据List<Animal> list20 = animalService.list(new LambdaQueryWrapper<Animal>().likeLeft(Animal::getName,"犬").gt(Animal::getAge,5));System.out.println(list20);}
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02), Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09)]
=======================
[Animal(name=西伯利亚雪橇犬, age=6, alias=二哈, description=富足家庭中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:14)]

不使用and默认就是and

(9)exists、notExists

exists:拼接EXISTS(sql语句),notExists:拼接NOT EXISTS(sql语句)

    @Testvoid contextExists(){//exists:拼接  查询age(年龄)大于6 的数据List<Animal> list21 = animalService.list(new LambdaQueryWrapper<Animal>().exists("select name,alias,description from animal where age > 6"));System.out.println(list21);}

查询结果显示  数据库版本有问题 说明不支持该版本的MySQL.导致数据结果不对. 

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2021-12-01 18:00:53.425  INFO 20440 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02), Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=孔雀, age=3, alias=白孔雀, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09), Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12), Animal(name=西伯利亚雪橇犬, age=6, alias=二哈, description=富足家庭中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:14), Animal(name=蓝猫, age=7, alias=猫, description=家养, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:16), Animal(name=大熊猫, age=8, alias=国宝, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:19)]

(10)orderByAsc、orderByDesc

orderByAsc:排序:ORDER BY 字段, … ASC,orderByDesc:排序:ORDER BY 字段, … DESC

    @Testvoid contextOrderByAsc(){//orderByAsc:升序  通过age(年龄)升序排序List<Animal> list22 = animalService.list(new LambdaQueryWrapper<Animal>().orderByAsc(Animal::getAge));System.out.println(list22);System.out.println("=============================");//orderByDesc:降序  通过age(年龄)降序排序List<Animal> list23 = animalService.list(new LambdaQueryWrapper<Animal>().orderByDesc(Animal::getAge));System.out.println(list23);}
[Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02), Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=孔雀, age=3, alias=白孔雀, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09), Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12), Animal(name=西伯利亚雪橇犬, age=6, alias=二哈, description=富足家庭中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:14), Animal(name=蓝猫, age=7, alias=猫, description=家养, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:16), Animal(name=大熊猫, age=8, alias=国宝, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:19)]
=============================
[Animal(name=大熊猫, age=8, alias=国宝, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:19), Animal(name=蓝猫, age=7, alias=猫, description=家养, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:16), Animal(name=西伯利亚雪橇犬, age=6, alias=二哈, description=富足家庭中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:14), Animal(name=边境牧羊犬, age=5, alias=边牧, description=家中, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:12), Animal(name=狮子, age=4, alias=辛巴, description=影视, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:09), Animal(name=孔雀, age=3, alias=白孔雀, description=北京动物园, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=东北虎, age=2, alias=大脑虎, description=东北地区, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 11:48:27), Animal(name=西伯利亚猩猩, age=1, alias=黑猩猩, description=西伯利亚, inputtime=2021-10-27 15:30:50, updatetime=2021-12-01 15:25:02)]

MybatisPlus条件构造器wrapper方法的使用相关推荐

  1. MybatisPlus学习(四)条件构造器Wrapper方法详解

    https://www.cnblogs.com/xianz666/p/13857733.html MybatisPlus学习(四)条件构造器Wrapper方法详解 文章目录 1.条件构造器 2.Que ...

  2. Mybatis-Plus 条件构造器Wrapper常用方法

    Mybatis-Plus 条件构造器Wrapper常用方法 下面拼接的也就是sql语句里面where后面的: 1.eq 匹配与键值相等的数据 eq(键,值) 2.ne 匹配与键值不相等的数据 ne(键 ...

  3. MybatisPlus学习 条件构造器Wrapper方法详解

    目录 1.条件构造器 2.AbstractWrapper 2.1.eq.allEq.ne. 2.2.gt.ge.lt.le 2.3.between.notBetween 2.4.like.notLik ...

  4. MyBatisPlus条件构造器排序方法orderByDesc参数怎样构造

    场景 项目搭建专栏: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/column/info/37194 基础搭建: https://blog.csdn.net/B ...

  5. Mybatis-Plus实战中的几个条件构造器Wrapper用法

    Mybatis-Plus实战中的几个条件构造器Wrapper用法 其实Wrapper有很多其他的方法,组合起来也是殊途同归,大家可以自己点开源码去查看一些方法的使用说明 @Testvoid conte ...

  6. MyBatisPlus条件构造器中last方法怎样使用

    场景 项目搭建专栏: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/column/info/37194 基础搭建: https://blog.csdn.net/B ...

  7. Mybatis-Plus条件构造器学习and方法

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 Mybatis-Plus条件构造器学习and方法 一.代码 1.Controller 2.Service 3.效果 一.代码 1.Co ...

  8. 第 4 章 MybatisPlus 条件构造器

    第 4 章 MybatisPlus 条件构造器 1.CRUD API 的思考 对于 BaseMapper 中基本 CRUD 方法的思考 继承了 BaseMapper 接口后,我们只能获得基本的 CRU ...

  9. MP条件构造器Wrapper

    5.1 概述 我们在实际操作数据库的时候会涉及到很多的条件.所以MP为我们提供了一个功能强大的条件构造器 Wrapper .使用它可以让我们非常方便的构造条件. ​ 其继承体系如下: ​ 在其子类Ab ...

最新文章

  1. 第三篇——第二部分——第六文 监控SQL Server镜像
  2. MySQL的安装与配置--windows下安装
  3. 场地测量的方法和程序_场地测量方案
  4. 为什么你设计的网页不够惊艳?
  5. VISIO2016的安装报错
  6. mysql create 无法使用_[转载]mysqlcreate新建用户host使用%,本地无法连接原因及解决方法 WesTward...
  7. 3.15 study 简单移动动画js实现
  8. aws云服务器会自动扣费吗,AWS云服务免费套餐竟然扣钱了?可能是因为你的region没管好...
  9. sql2000 指定的服务器不存在,SQL Server 2000服务无法启动,提示“系统找不到指定的文件”解决方法及sp4安装不上...
  10. win10自动修复失败无限循环_windows自动修复失败,无法启动
  11. 数字1、2、3、4能组成多少个互不相同且无重复数字的三位数,并将其输出。
  12. 计算机组成原理:2. 计算机的发展及应用
  13. html标签中加入颜色,html怎么给span添加颜色
  14. 站稳前三之后,新华三大数据亮剑三大新能力
  15. 可视化软件grafana如何用oauth实现第三方授权登录
  16. Arcmap转nc文件为TIFF格式(以逐月降水量数据集转年均数据为例)
  17. vue导入及使用本地图片
  18. 小黑记事本怎样设置html,小黑记事本如何使用便签 设置便签的方法
  19. 英语自我介绍(工作求职)
  20. 【演示文稿制作软件】Focusky教程 | 设置动画效果

热门文章

  1. Unity3d插件分享之Assetbundle工具2021最好用工具没有之一
  2. 2019第二届中国智慧零售终端大会
  3. 博客园自定义鼠标样式
  4. 7天学习Go语言-尾声+一次险些翻车的任意文件读取漏洞小记
  5. 在Java 应用程序中访问USB设备
  6. LVS模式一:DR模式(ipvsadm)
  7. 仙剑奇侠传1 通关记录
  8. 好看又有趣的404页面设计
  9. 火狐浏览器下载最后一秒卡住怎么办?
  10. Java英汉翻译程序_java实现简单的英文文本单词翻译器功能示例