mybatis在<if>中传入一个简单类型参数的两种写法。
第一使用注释:
public long getAllCustomerQuantity(@Param("mobileFlag") boolean mobileFlag);
<select id="getAllCustomerQuantity" resultType="java.lang.Long" parameterType="boolean">
SELECT COUNT(*) FROM CUSTOMER AS cutomer WHERE cutomer.USE_FLAG = 1;
<if test="mobileFlag == true">
AND cutomer.STATUS_CODE='2'
</if>
</select>
第二使用_parameter:
public long getAllCustomerQuantity(boolean mobileFlag);
<select id="getAllCustomerQuantity" resultType="java.lang.Long" parameterType="boolean">
SELECT COUNT(*) FROM CUSTOMER AS cutomer WHERE cutomer.USE_FLAG = 1;
<if test="_parameter == true">
AND cutomer.STATUS_CODE='2'
</if>
</select>
最后,如果不是在<if>标签中,也可以按下面的方式写:
这时候mobileFlag这个参数叫什么名称都无所谓了。
public long getAllCustomerQuantity(boolean mobileFlag);
<select id="getAllCustomerQuantity" resultType="java.lang.Long" parameterType="boolean">
SELECT COUNT(*) FROM CUSTOMER AS cutomer WHERE cutomer.USE_FLAG = 1;
AND cutomer.STATUS_CODE=#{mobileFlag}
</select>