mybatis傳入多個引數
阿新 • • 發佈:2018-11-08
方案一:
public List<XXXBean> getXXXBeanList(String xxId, String xxCode);
<select id="getXXXBeanList" resultType="XXBean">
select t.* from tableName where id = #{0} and name = #{1}
</select>
由於是多引數那麼就不能使用parameterType, 改用#{index}是第幾個就用第幾個的索引,索引從0開始
方案二(基於註解):
public int delCart(@Param("username")String username,@Param("ids")List<Integer> ids); <delete id="delCart"> delete from carts where username=#{username} and cid in <foreach collection="ids" item="cid" open="(" separator="," close=")"> #{cid} </foreach> </delete> 由於是多引數那麼就不能使用parameterType, 這裡用@Param來指定哪一個