中国在我心中演讲稿
如何将⼀个list传⼊到mySql语句进⾏查询如何将⼀个list传⼊到mySql语句进⾏查询
proudly⽅法(⼀)
将list封装成⼀个Map传⼊进去
//(1)将如下字符串分隔之后放⼊到list⾥⾯
小学四年级英语课件String cols = ”1,2,3,4,5,6”;
List<String> yids = new ArrayList<String>();
String[] as = cols.split(",");
for(String s : as){
yids.add(s);
}
//(2)将list放到Map⾥⾯,正常的传⼊到后台
Map<String, Object> map2 = new HashMap<String, Object>();
Long productId = 1111;
map2.put("ids", yids);
map2.put("productId", productId);
specDataMapper.updateInvalidByProductIdAndCols1(map2);
工夫的意思mapper中sql语句如下
<update id="updateInvalidByProductIdAndCols1">
update tbl_mall_spec_data
t invalid = 1
where product_id = #{productId,jdbcType=BIGINT}
cet4
and cols1 not in
/
/注意connection⾥⾯是ids item⾥⾯就是传过来的集合me too什么意思
<foreach collection="ids" item="item" index="index" open="(" parator="," clo=")">
#{item}
</foreach>
</update>
⽅法(⼆)driver
(1)将如下字符串分隔之后放⼊到list⾥⾯
Long productId = 1111;
新动力学校String cols = ”1,2,3,4,5,6”;
List<String> yids = new ArrayList<String>();
String[] as = cols.split(",");
for(String s : as){
yids.add(s);
}
castlerock
specDataMapper.updateInvalidByProductIdAndCols1(yids,productId);
(2)rvice注意 由于传进去的是两个参数 所以需要加上@Param 否者不会识别此参数
carrier是什么意思
List<SysModel> getModelListByIds(@Param List<String> ids,@Param Long productId);
(3)mapper中sql语句如下
<update id="updateInvalidByProductIdAndCols1">
update tbl_mall_spec_data
t invalid = 1
where product_id = #{productId,jdbcType=BIGINT}
and cols1 not in
//注意由于直接传⼊的是list所以connection⾥⾯是list item⾥⾯就是传过来的集合
<foreach collection="list" item="item" index="index" open="(" parator="," clo=")">
#{item}
</foreach>
</update>