<insert id="insertAwardPic" useGeneratedKeys="true" parameterType="java.util.List">
<selectKey resultType="long" keyProperty="id" order="AFTER">
SELECT
LAST_INSERT_ID()
</selectKey>
insert into check_awardspics
(award_id,picurl,create_date)
values
<foreach collection ="list" item="CheckAwardspics" index= "index" separator =",">
(#{CheckAwardspics.awardId},#{CheckAwardspics.picUrl},now())
</foreach>
</insert>
========================================================
public int insertAwardPic(List<CheckAwardspics> checkAwardspicsList);
/**
* 添加奖品的图片
* @param checkAwardspics
* @return
*/
public int insertAwardPic(List<CheckAwardspics> checkAwardspicsList){
int count=0;
try{
count=checkAwardspicsDao.insertAwardPic(checkAwardspicsList);
}catch(Exception e){
logger.error("添加奖品的图片出现异常! e:"+e);
}
return count;
}
=================================================
//批量插入数据图片
CheckAwardspics checkAwardspics=null;
if(StringUtils.isNoneEmpty(picUrl)){
HashSet hset = new HashSet(Arrays.asList(picUrl));
Iterator i = hset.iterator();
while(i.hasNext()){
checkAwardspics=new CheckAwardspics();
checkAwardspics.setAwardId(checkAwardsB.getId());
checkAwardspics.setPicUrl(String.valueOf(i.next()));
checkAwardspicsList.add(checkAwardspics);
}
}
=================================================================
if(!checkAwardspicsList.isEmpty()&&checkAwardspicsList.size()>0){
awardRecordService.deletePics(String.valueOf(checkAwardsB.getId()));//插入图片的时候先将原来的图片清空
countB=awardRecordService.insertAwardPic(checkAwardspicsList);
}