首页 > 其他分享 >02,mybatise批量插入

02,mybatise批量插入

时间:2022-10-22 13:44:32浏览次数:53  
标签:02 map 批量 toProperty birthDate mybatise session id

SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH);
try {
SimpleTableMapper mapper = session.getMapper(SimpleTableMapper.class);
List records = getRecordsToInsert(); // not shown

BatchInsert<SimpleTableRecord> batchInsert = insert(records)
        .into(simpleTable)
        .map(id).toProperty("id")
        .map(firstName).toProperty("firstName")
        .map(lastName).toProperty("lastName")
        .map(birthDate).toProperty("birthDate")
        .map(employed).toProperty("employed")
        .map(occupation).toProperty("occupation")
        .build()
        .render(RenderingStrategy.MYBATIS3);

batchInsert.insertStatements().stream().forEach(mapper::insert);

session.commit();

} finally {
session.close();
}

标签:02,map,批量,toProperty,birthDate,mybatise,session,id
From: https://www.cnblogs.com/NIAN2011/p/16754779.html

相关文章