mysql数据库不支持"||"拼接字符串,替代函数contact踩坑过程:
contact用法举例:
mybatis/mybatisPlus实例:
<if test="queryParams.companyAddress != null and queryParams.companyAddress.trim() != '' and queryParams.selectWhere.companyAddress != null"> AND concat( temp.organ_province_name, temp.organ_city_name, temp.organ_county_name, temp.organ_town_name, temp.organ_address ) ${queryParams.selectWhere.companyAddress } </if>
结果:
乍一看完了,查询没有问题,但是经过本人测试之后发现,concat函数拼接字符串的时候,里面只要有空值,整个数据拼接结果就是空的
例如:concat(
temp.organ_province_name,
temp.organ_city_name,
temp.organ_county_name,
temp.organ_town_name,
temp.organ_address
)
里面如果organ_town_name这个是空,即便是其他有值,结果也是空
改造之后的函数,添加ifnull()函数,功能和oracle的nvl类似
<if test="queryParams.companyAddress != null and queryParams.companyAddress.trim() != '' and queryParams.selectWhere.companyAddress != null">
AND concat(
IFNULL(temp.organ_province_name,""),
IFNULL(temp.organ_city_name,""),
IFNULL(temp.organ_county_name,""),
IFNULL(temp.organ_town_name,""),
IFNULL(temp.organ_address,"")
) ${queryParams.selectWhere.companyAddress }
</if>
完美解决!起飞!!!