mybatis sql使用经验总结
1、where 后面如果有动态sql,可以添加一个1=1条件,然后在后面添加动态sql语句,里面添加AND
例如:
<select id="queryBizMonitorHistoryByNodeIds" resultType="com.huawei.cbc.cloudbi.analysis.entity.BizMonitorHistory"> SELECT cardId, monitorTime, status, checkCount FROM t_ac_monitor_history where 1=1 <if test="nodeIds != null"> AND nodeId IN <foreach collection="nodeIds" item="nodeId" open="(" close=")" separator=","> #{nodeId} </foreach> </if> <if test="status != null"> AND status=#{status} </if> </select>