mybatis中註解式開發中傳遞多個引數的方式
阿新 • • 發佈:2019-01-29
在mybatis的動態代理開發中,當介面需要傳入多個引數時,一般有以下幾種做法(推薦@Param方式)
1.傳遞包裝型別(不推薦要建立一個包裝類去包含所有的引數型別,並且在#{}中還要填入特定的值)
2.假設介面中傳入兩個引數則#{0}代表第一個引數,以此類推
<select id="xxxxx" >
select * from xxxxxx where xxx = #{0} and xxxx=#{1}
</select>
3.新增@Param註解
int deleteProductCategory(@Param("shopId")Long shopId,@Param("productCategoryId")Long productCategoryId);
<delete id="deleteProductCategory" >
DELETE FROM
tb_product_category
WHERE
shop_id=#{shopId}
AND
product_category_id=#{productCategoryId}
</delete>
取得時候#{xx}xx填寫註解中標註的內容即可,可讀性高,方便,不易出錯,推薦