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

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

mybatis 批量更新(batchUpdate)

2019-11-10 19:37:33
字體:
來(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)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 定日县| 石狮市| 广水市| 弥渡县| 晋中市| 崇明县| 台湾省| 敦化市| 关岭| 罗源县| 柘城县| 正安县| 卓尼县| 崇礼县| 九龙城区| 沁源县| 丰台区| 谢通门县| 鄂温| 石楼县| 罗山县| 于田县| 奉节县| 仪征市| 营山县| 延庆县| 乌审旗| 安福县| 甘孜县| 山阳县| 海口市| 镇原县| 平遥县| 靖西县| 来宾市| 东乡| 金山区| 天等县| 禹州市| 兴海县| 高邮市|