public int [ ] batchSave ( List < ? extends Model > modelList , int batchSize ) { if ( modelList == null || modelList . size ( ) == 0 ) return new int [ 0 ] ; Model model = modelList . get ( 0 ) ; Map < String , Object > attrs = model . _getAttrs ( ) ; int index = 0 ; StringBuilder columns = new StringBuilder ( ) ; // the same as the iterator in Dialect.forModelSave() to ensure the order of the attrs for ( Entry < String , Object > e : attrs . entrySet ( ) ) { if ( config . dialect . isOracle ( ) ) { // 支持 oracle 自增主键 Object value = e . getValue ( ) ; if ( value instanceof String && ( ( String ) value ) . endsWith ( ".nextval" ) ) { continue ; } } if ( index ++ > 0 ) { columns . append ( ' ' ) ; } columns . append ( e . getKey ( ) ) ; } StringBuilder sql = new StringBuilder ( ) ; List < Object > parasNoUse = new ArrayList < Object > ( ) ; config . dialect . forModelSave ( TableMapping . me ( ) . getTable ( model . getClass ( ) ) , attrs , sql , parasNoUse ) ; return batch ( sql . toString ( ) , columns . toString ( ) , modelList , batchSize ) ; }
Batch save models using the insert into ... sql generated by the first model in modelList . Ensure all the models can use the same sql as the first model .