国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

mybatis 批量更新(batchUpdate)

2019-11-10 17:31:02
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

第一:修改數(shù)據(jù)庫(kù)的連接方式 &&allowMultiQueries=true

比如:jdbc/:MySQL/://rdshme0env6yf2n829ympublic.mysql.rds.aliyuncs.com/wlsq_dev_test?useUnicode/=true&characterEncoding/=utf8&allowMultiQueries=true

mybatis 配置文件:

   <!--批量修改密碼  -->   <update id="updateBatch" parameterType="java.util.List">              <foreach collection="list" item="item" index="index" open="" close="" separator=";">				update account set `passWord` = #{item.password} where acct_id = #{item.acctId}					       </foreach>   </update>  

dao 層

  public void updateBatch(List<Account> list);

service 層

  public void updateBatch(List<Account> list);service 實(shí)現(xiàn)層

	public void updateBatch(List<Account> list) {		// TODO Auto-generated method stub		this.accountMapper.updateBatch(list);	}

controller 層

 @RequestMapping({"/batchupdate"})  @ResponseBody  public String batchUpdate(){	  String result = "";	  try{	  List<Account> list = accountService.batchUpdate();	  List<Account> batch = new ArrayList<Account>();	  	 	  //密碼修改	  if(list !=null && list.size()>0){		  for(int i=0;i<list.size();i++){			  Account account =list.get(i);			  String oldpassword = account.getPassword();			  account.setPassword(EncryptUtils.encodeBase64String(oldpassword));			  batch.add(account);		  }	  }	  //一次處理數(shù)據(jù)量	  int  init = 1000;// 每隔1000條循環(huán)一次  =1000;	  //總數(shù)	  int nums = batch.size();	  //批次數(shù)	  int batchnum = nums / init;  	  if (nums % init != 0) {  		  batchnum += 1;            if (nums < init) {                init = list.size();            }        } 	  	   for (int i = 0; i < batchnum; i++) {             System.out.PRintln("------" + i + "保存"+init+"條數(shù)據(jù)到數(shù)據(jù)庫(kù)....");             List<Account> a = new ArrayList<Account>();           if (i == batchnum - 1) {                 int size = (i + 1) * init;                 for (int j = size - init; j < nums; j++) {              	   if (batch.get(j) == null) {                         break;                     }             	   a.add(batch.get(j));                 }                           } else {                 int size = (i + 1) * init;                 for (int j = size - init; j < size; j++) {             	   if (batch.get(j) == null) {                         break;                     }              	   a.add(batch.get(j));                 }                          }             accountService.updateBatch(a);                 }  	  	 		  	  }catch(Exception e){		  System.out.println(e.getMessage());		  return "false";	  }	  result = "true";	  return result;	    }結(jié)果展示:


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 陵水| 万盛区| 泰顺县| 大同市| 上饶市| 五莲县| 招远市| 垣曲县| 阿鲁科尔沁旗| 延川县| 义马市| 射洪县| 诏安县| 万宁市| 澄迈县| 宝清县| 磐安县| 察雅县| 德清县| 鄂温| 芦山县| 三都| 大余县| 拜泉县| 金寨县| 瑞丽市| 伽师县| 石泉县| 宜黄县| 凤凰县| 河间市| 依兰县| 公主岭市| 正定县| 札达县| 济南市| 泸州市| 泰兴市| 桂林市| 奎屯市| 区。|