admin管理员组

文章数量:1599529

作用

字段 where 实体查询比较条件,有值设置则按设置的值为准,没有则为默认全局的 %s=#{%s}

使用

实体类添加注解

package com.liulong.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student {
    @TableId(type = IdType.AUTO)
    private long id;
    @TableField(condition = SqlCondition.LIKE)
    private String name;
}

关于类SqlCondition,里面还定义了其他比较模式,可自行查看

使用queryMapper,调用setEntity方法封装查询条件

@Test
    public void test(){
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(new Student(1,"xxxxx"));
        studentMapper.selectList(queryWrapper).forEach(System.out::println);
    }

最终显示的sql语句为

当变换condition属性值时,相应的sql语句也会改变

本文标签: 属性TableFieldcondition