1. 程式人生 > >實現MyBatis批量更新

實現MyBatis批量更新

Service

        public int updateList(List<PigInfoEntity> entity);

ServiceImpl

	public int updateList(List<PigInfoEntity> entity){
		logger.info("PigInfoServiceImpl ==> updateList()");
		return pigInfoDao.updateList(entity);
		
	}

Dao 

        public int updateList(List<PigInfoEntity> entity);

DaoImpl

	@Override
	public int updateList(List<PigInfoEntity> entity){
		logger.info("PigInfoDaoImpl ==> updateList()");
		return getWriteSession().update(sqlId("updateList"),entity);		
	}

Mapper

	<update id="updateList" parameterType="java.util.List" >
	<foreach collection="list" item="item" index="index" open="" close="" separator=";">
	 update t_pig_info 
	 	<set>
	 		     update_time=now(),
			     update_user='${item.update_user}'
		</set>
		where id='${item.id}' and del_flag='0'
		    </foreach>
	</update>