<if test="day !=null and day != ''">
and day=#{day}
</if>
一直知道在mybatis中有这个标签,但是现在才知道有什么作用,在一些方法里,有些参数会传null,或者“ ”,即不传参数,这就需要这个标签进行判断
Double selectIncome(@Param("incomeType")Integer incomeType,@Param("plantId") Integer plantId, @Param("day")Integer day, @Param("tableName")String tableName1);
day和incomeType可以为null,那么就要检验这两个条件是否要省略
<select id="selectIncome" resultType="java.lang.Double">
select income earnings from ${tableName} where plantId=#{plantId}
<if test="day !=null and day != ''">
and day=#{day}
</if>
<if test="incomeType !=null and incomeType != ''">
and incomeType=#{incomeType}
</if>
</select>