| | |
| | | import org.apache.ibatis.mapping.MappedStatement; |
| | | import org.apache.ibatis.mapping.SqlSource; |
| | | |
| | | /** |
| | | * 批量插入方法 |
| | | * @author WWW |
| | | */ |
| | | @SuppressWarnings("ALL") |
| | | public class InsertBatchMethod extends AbstractMethod { |
| | | /** |
| | | * insert into user(id, name, age) values (1, "a", 17), (2, "b", 18); |
| | | * <script> |
| | | * insert into user(id, name, age) values |
| | | * <foreach collection="list" item="item" index="index" open="(" separator="),(" close=")"> |
| | | * #{item.id}, #{item.name}, #{item.age} |
| | | * </foreach> |
| | | * </script> |
| | | */ |
| | | @Override |
| | | public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) { |
| | | final String sql = "<script>insert into %s %s values %s</script>"; |
| | |
| | | |
| | | SqlSource sqlSource = languageDriver.createSqlSource(configuration, sqlResult, modelClass); |
| | | |
| | | // 第三个参数必须和RootMapper的自定义方法名一致 |
| | | return this.addInsertMappedStatement(mapperClass, modelClass, "insertBatch", sqlSource, new NoKeyGenerator(), null, null); |
| | | } |
| | | |