實現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>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章