批量操作
~~~
@Resource(name = "sqlSessionDao")
private Dao dao;
//批量插入
List<TfNList> list = new ArrayList();
TfNList n1 = new TfNList();
n1.setListId("111");
n1.setListName("測試");
list.add(n1);
TfNList n2 = new TfNList();
n2.setListId("112");
n2.setListName("測試2");
list.add(n2);
dao.insertBatch(list);
//批量插入另一種寫法
dao.insertBatch(new ArrayList(){{
add(new TfNList(){{
setListId("111");
setListName("測試");
}});
add(new TfNList(){{
setListId("112");
setListName("測試2");
}});
}});
//批量更新
List<TfNList> list = new ArrayList();
TfNList n1 = new TfNList();
n1.setListId("111").asCondition();
n1.setListName("測試");
list.add(n1);
TfNList n2 = new TfNList();
n2.setListId("112").asCondition();
n2.setListName("測試2");
list.add(n2);
dao.updateBatch(list);
//批量更新另一種寫法
dao.updateBatch(new ArrayList(){{
add(new TfNList(){{
setListId("111").asCondition();;
setListName("測試");
}});
add(new TfNList(){{
setListId("112").asCondition();;
setListName("測試2");
}});
}});
//設置條件時,調用每個實體類asCondition()方法是一種方式,還有另外一種方法,可指定條件列,方法定義如下:
updateBatch(List<? extends BaseEntity> list, String... conditionColumns);
//用法如下
dao.updateBatch(list, "LIST_ID", "CUST_TYPE");
//批量刪除
List<TfNList> list = new ArrayList();
TfNList n1 = new TfNList();
n1.setListId("111").asCondition();
list.add(n1);
TfNList n2 = new TfNList();
n2.setListId("112").asCondition();
list.add(n2);
dao.deleteBatch(list);
//批量刪除另一種寫法
dao.deleteBatch(new ArrayList(){{
add(new TfNList(){{
setListId("111").asCondition();;
}});
add(new TfNList(){{
setListId("112").asCondition();;
}});
}});
//技巧:此種寫法目的是減少遍歷次數,某些值可不用事先設置,在BatchEachHandler里進行處理即可,insertBatch內部循環時會回調BatchEachHandler
dao.insertBatch(list, new BatchEachHandler<TfNList>(){
@Override public void onEach(TfNList n){
n.setCreateTime(new Date());
}
});
//另外也可自定義sql進行批量處理
void executeBatch(String statementId, List<?> list);
void executeBatch(String statementId, List<?> list, BatchEachHandler batchEachHandler);
~~~
- walk簡介
- 核心模塊
- walk-data
- IData
- EntityHelper
- walk-cache
- 緩存管理器
- 緩存對象
- 緩存注解
- walk-batis
- 單表操作
- 批量操作
- 列表/分頁查詢
- 所有方法列表
- sql熱部署
- 二級緩存
- 數據庫方言
- 其他使用技巧
- 實體類生成工具
- walk-mq
- 隊列管理器
- 隊列對象
- 訂閱/發布管理器
- 訂閱器
- 發布器
- walk-shiro
- 用戶認證/授權
- url動態授權/回收
- 分布式會話
- 無狀態會話支持
- walk-base
- 前端基礎框架
- 公共頁面
- 自定義標簽
- 自定義函數
- 組件及工具
- 后端基礎框架
- 基礎結構
- 表單校驗
- 數據導入
- 數據導出
- 上傳下載
- 靜態參數加載器
- 靜態參數翻譯器
- 實體類翻譯器
- sql翻譯器
- 自定義翻譯器
- 靜態參數校驗器
- 分布式任務
- 增刪改查代碼生成器
- walk-restful
- 請求報文
- 返回報文
- 節點翻譯器
- api代碼生成
- walk-activiti
- 接口封裝
- 模型管理
- 流程圖展示
- 集成方法
- walk-console
- 在線會話管理
- 靜態參數表緩存管理
- 緩存管理
- 隊列管理
- 發布/訂閱管理
- walk-boot
- 常用功能
- 持久層操作
- 分布式緩存
- 分布式會話
- 分布式任務
- 前端常用功能
- 后端常用功能
- 工作流封裝
- 多數據源支持
- 關于讀寫分離
- 常用工具類
- 代碼生成工具
- SpringCloud集成
- 阿里edas平臺支持
- 其他
- 開發規約
- 環境要求
- 工程示例
- 工程結構
- web工程
- API工程
- 后臺任務
- 常見問題
- 事務不生效
- 分布式任務不生效
- 事務鎖
- 變更歷史