# eq 、ne 的使用
LambdaQueryWrapper<TbPersonEntity> wrapper = new LambdaQueryWrapper<TbPersonEntity>()
.eq(TbPersonEntity::getPersonId,personId)
.ne(TbPersonEntity::getNotarType,notarType);
# in 用法
# 根据id的集合查询
# selectBatchIds 是 mybatis-plus (BaseMapper)封装好的
第一种方式:
@Override
public List<SysRoleEntity> selectListBySysRoleIdList(List<String> sysRoleIdList) {
return sysRoleDao.selectBatchIds(sysRoleIdList);
}
# 如果不是主键id的集合,可以使用第二种
第二种方式:
@Override
public List<SysRoleEntity> selectListBySysRoleIdList(List<String> sysRoleIdList) {
LambdaQueryWrapper<SysRoleEntity> wrapper = new LambdaQueryWrapper<SysRoleEntity>()
.in(SysRoleEntity::getSysRoleId,sysRoleIdList);
return sysRoleDao.selectList(wrapper);
// return sysRoleDao.selectBatchIds(sysRoleIdList);
}
# 排序 orderByAsc 、orderByDesc等
@Override
public List<SysRoleEntity> selectListByTypeCode(String typeCode) {
LambdaQueryWrapper<SysRoleEntity> wrapper = new LambdaQueryWrapper<SysRoleEntity>()
.eq(SysRoleEntity::getTypeCode,typeCode)
.orderByAsc(SysRoleEntity::getSysRoleId);
return sysSysRoleDao.selectList(wrapper);
}
# 如果排序的字段需要先转换类型呢
# 那么就需要 sql自由拼接方法 (wrapper.apply)
@Override
public List<SysRoleEntity> selectListByTypeCode(String typeCode) {
LambdaQueryWrapper<SysRoleEntity> wrapper = new LambdaQueryWrapper<SysRoleEntity>()
.eq(SysRoleEntity::getTypeCode,typeCode)
.apply("ORDER BY TO_NUMBER(SEQUENCEVALUE) ASC");
}
# or 用法
@Override
public List<SysRoleEntity> selectListByTypeCode(String typeCode) {
LambdaQueryWrapper<SysRoleEntity> wrapper = new LambdaQueryWrapper<SysRoleEntity>()
.eq(SysRoleEntity::getTypeCode,typeCode)
.and(wq -> wq
.eq(SysRoleEntity::getType , "01"))
.or()
.eq(SysRoleEntity::getType , "02");
}
# 生成SQL
typeCode = #typeCode# AND (type = '01' or type = '02')
# selectCount 查询数据条数
@Override
public boolean validateExist(String type) {
LambdaQueryWrapper<SysRoleEntity> wrapper = new LambdaQueryWrapper<SysRoleEntity>()
.eq(SysRoleEntity::getType , type);
return sysRoleDao.selectCount(wrapper) > 0;
}
# isNotNull
@Override
public List<SysRoleEntity> getChildrenList() {
LambdaQueryWrapper<SysRoleEntity> wrapper = new LambdaQueryWrapper<SysRoleEntity>()
.isNotNull(SysRoleEntity::getType);
return sysRoleDao.selectList(wrapper);
}