QueryWrapper不等于函数
时间: 2024-12-26 11:26:35 浏览: 57
使用QueryWrapper实现不等于查询
在MyBatis-Plus中,QueryWrapper
提供了多种方法用于构建不同的查询条件。对于不等于查询,可以通过 ne
方法来设置字段与给定值不相等的条件[^1]。
下面是一个具体的例子,假设有一个学生实体类 Student
和对应的Mapper接口 StudentMapper
:
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class StudentService {
@Autowired
private StudentMapper studentMapper;
public List<Student> getStudentsNotInClass(String className) {
QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
// 设置班级名称不等于指定值
queryWrapper.ne("class_name", className);
return studentMapper.selectList(queryWrapper);
}
}
此代码片段展示了如何利用 QueryWrapper
的 ne
方法设定 “班级名称(class_name)” 字段与传入参数 className
不匹配作为查询条件,从而获取不属于特定班级的所有学生记录[^2]。
此外,在实际应用中还可以链式调用其他的方法进一步细化查询逻辑,比如增加更多的过滤条件或是排序规则等[^3]。
阅读全文
相关推荐


















