下面的史对的
<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