国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 织金县| 巴里| 北票市| 喀喇沁旗| 屏山县| 乌苏市| 榆树市| 临西县| 潼关县| 武定县| 哈尔滨市| 安顺市| 吉水县| 昆山市| 会理县| 基隆市| 噶尔县| 福海县| 民县| 宁阳县| 肥西县| 合作市| 正阳县| 贡觉县| 上高县| 马边| 武夷山市| 余姚市| 三门县| 盐亭县| 彩票| 杨浦区| 永嘉县| 清徐县| 维西| 珲春市| 英超| 鄂托克前旗| 武邑县| 巴塘县| 黄石市|