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

首頁 > 學院 > 開發設計 > 正文

mybatis 批量更新(batchUpdate)

2019-11-10 17:23:09
字體:
來源:轉載
供稿:網友

第一:修改數據庫的連接方式 &&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 實現層

	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);		  }	  }	  //一次處理數據量	  int  init = 1000;// 每隔1000條循環一次  =1000;	  //總數	  int nums = batch.size();	  //批次數	  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+"條數據到數據庫....");             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;	    }結果展示:


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 偏关县| 佛冈县| 高陵县| 阆中市| 青铜峡市| 长春市| 隆化县| 祁阳县| 花莲县| 磐安县| 宜章县| 安陆市| 夹江县| 兰溪市| 八宿县| 江安县| 洛阳市| 霍林郭勒市| 开阳县| 汉阴县| 睢宁县| 成都市| 阜新市| 车致| 万州区| 郯城县| 蒙山县| 乌恰县| 西乡县| 皋兰县| 营山县| 古浪县| 东丰县| 滁州市| 金湖县| 缙云县| 崇仁县| 安仁县| 西林县| 临高县| 荆门市|