2
我已經寫在我的mapper.xml
我將如何傳遞參數,並檢查它在MyBatis的動態查詢創建
<select id="getCatCount" parameterType="String" resultType="int">
select count(*) from Categories where status is not null
<if test="catTypeId != 0">
AND cat_type_id = #{catTypeId,jdbcType=INTEGER}
</if>
</select>
和mapper.java方法的選擇查詢
int getCatCount(int catTypeId);
我如何檢查在if條件中爲catTypeId。我知道上面的語句是不正確的,但我想把這樣的條件,所以我檢查catTypeId是否不爲零,然後只添加AND條件。或者我需要傳遞Category類的整個對象嗎?
非常感謝Jddsantaella多一次和非常好的解釋。 – user965884
不客氣。 – jddsantaella
這真的幫助我理解一個新的api怪癖 – Stevko