admin管理员组文章数量:1599428
作用
字段 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
版权声明:本文标题:@TableField condition属性 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1728322177a1153969.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论