关于MybatisPlus查询条件 or 并集 某字段空字符串和NULL问题 sql

下面的史对的

	<select id="getHouseIsExist" resultType="com.easy.hotel.pms.api.entity.House" >
		select *  from   house h
		<where>
			h.del_flag ='0'
			<if test="estateId != null and estateId != ''">
				and h.estate_id =#{estateId}
			</if>

			<choose>
				<when test="court != null">
					AND h.court_id =#{court.courtId}
				</when>
				<otherwise>
					AND h.court_id  is null
				</otherwise>
			</choose>

			<choose>
				<when test="build != null">
					AND h.build_id = #{build.buildId}
				</when>
				<otherwise>
					AND h.build_id  is null
				</otherwise>
			</choose>

			<choose>
				<when test="buildUnit != null">
					AND h.unit_id = #{buildUnit.unitId}
				</when>
				<otherwise>
					AND h.unit_id  is null
				</otherwise>
			</choose>

			<choose>
				<when test="buildFloor != null">
					AND h.floor_id = #{buildFloor.floorId}
				</when>
				<otherwise>
					AND h.floor_id  is null
				</otherwise>
			</choose>

			<choose>
				<when test="houseNo != null and houseNo != ''">
					AND h.house_no = #{houseNo}
				</when>
				<otherwise>
					AND (  h.house_no is null or  h.house_no =''  )
				</otherwise>
			</choose>

		</where>


	</select>

 下面的不对

	@Override
	public List<House> getHouseList(Long estateId, Court court, Build build, BuildUnit buildUnit, BuildFloor buildFloor, String houseNo) {
		LambdaQueryWrapper<House> wrapper = new LambdaQueryWrapper<>();
		if(estateId != null){
			wrapper.eq(House::getEstateId, estateId);
		}
		if(court != null){
			wrapper.eq(House::getCourtId, court.getCourtId());
		}
		if(court == null){
			wrapper.isNull(House::getCourtId);
		}
		if(build != null){
			wrapper.eq(House::getBuildId, build.getBuildId());
		}
		if(build == null){
			wrapper.isNull(House::getBuildId);
		}
		if(buildUnit != null){
			wrapper.eq(House::getUnitId, buildUnit.getUnitId());
		}
		if(buildUnit == null){
			wrapper.isNull(House::getUnitId);
		}
		if(buildFloor != null){
			wrapper.eq(House::getFloorId, buildFloor.getFloorId());
		}
		if(buildFloor == null){
			wrapper.isNull(House::getFloorId);
		}
		if(StringUtils.isNotBlank(houseNo)){
			wrapper.eq(House::getHouseNo, houseNo);
		}
        //某个字段为空或者空字符串
		List houseNoList = new ArrayList();
		houseNoList.add(null);
		houseNoList.add("");   这种不对
		if(StringUtils.isBlank(houseNo)){
			//wrapper.isNull(House::getHouseNo).or(w -> w.eq(House::getHouseNo, ""));
			//AND house_no in(null,'')
			wrapper.in(House::getHouseNo,houseNoList);
		}
		List<House> list = baseMapper.selectList(wrapper);
		return list;
	}
SELECT
	house_id,
	estate_id,
	lane_id,
	street_num_id,
	build_id,
	floor_id,
	unit_id,
	house_no,
	house_name,
	house_code,
	house_sort,
	pnote,
	address,
	built_area,
	use_area,
	user_id,
	user_num,
	landlord_id,
	landlord_name,
	landlord_mobile,
	build_time,
	in_time,
	out_time,
	curdsts,
	flag,
	house_type,
	house_layout,
	sale_flag,
	use_flag,
	fit_type,
	rent_flag,
	nature_type,
	other_type,
	other_area,
	STATUS,
	note,
	state,
	create_time,
	create_id,
	update_time,
	update_id,
	tenant_id,
	del_flag,
	ty_id,
	court_id,
	grid_id 
FROM
	house 
WHERE
	(
		estate_id =  1463063056106917940
		AND court_id IS NULL 
		AND build_id = 1450294876624130799
		AND unit_id IS NULL 
		AND floor_id IS NULL 
		AND house_no IN ( null, '' )    这种不对
	) 
	AND tenant_id = 1433396810122006530

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值