进行了一个条件判断的查询,正常输入参数的时候都是好好的,只有当两个参数都为空的时候就会查不出数据
<select id="getAllDashboards" resultMap="dashboard">
SELECT
<include refid="baseColumns"/>
FROM t_dashboard
WHERE delete_flag='0'
<if test="isShared !=null'">
AND is_shared=#{isShared}
</if>
<if test="dashboardName!= null">
AND dashboard_name LIKE CONCAT(CONCAT('%', #{dashboardName}), '%')
</if>
ORDER BY update_time DESC , create_time DESC limit
</select>
当时的xml是这样的
因为在apizza没有测成功(这个是写文档和测试的一个工具,很好用)
我在于是sevice测试没想到测试成功了,这就很容易误导思路啊,还以为是参数传递的问题
最后问题解决了,还是xml的问题,正确的是这样的
<select id="getAllDashboards" resultMap="dashboard">
SELECT
<include refid="baseColumns"/>
FROM t_dashboard
WHERE delete_flag='0'
<if test="isShared !=null and isShared!= ''">
AND is_shared=#{isShared}
</if>
<if test="dashboardName!= null and dashboardName!=''">
AND dashboard_name LIKE CONCAT(CONCAT('%', #{dashboardName}), '%')
</if>
ORDER BY update_time DESC , create_time DESC limit
</select>
isShared !=null and isShared!= ''
这个添上去就可以了
其实这个错误也不是很难找,关键就是粗心,写代码的时候太想当然了,就认为这里都判断了null了,怎么会错,事实上不仅粗心大意还浪费了很多时间