1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
2
<!--
3
3
4
- Copyright 2010-2018 the original author or authors.
4
+ Copyright 2010-2019 the original author or authors.
5
5
6
6
Licensed under the Apache License, Version 2.0 (the "License");
7
7
you may not use this file except in compliance with the License.
@@ -177,11 +177,15 @@ public MyBatisCursorItemReader<Employee> reader() {
177
177
<subsection name =" MyBatisBatchItemWriter" >
178
178
179
179
<p >
180
- 这是一个 <code >ItemWriter</code >,通过利用 <code >SqlSessionTemplate</code > 中的批量处理功能来对给定的所有记录执行多个语句。<code >SqlSessionFactory</code > 需要被配置为 <code >BATCH</code > 执行类型。
180
+ 这是一个 <code >ItemWriter</code >,通过利用 <code >SqlSessionTemplate</code >
181
+ 中的批量处理功能来对给定的所有记录执行多个语句。<code >SqlSessionFactory</code >
182
+ 需要被配置为 <code >BATCH</code > 执行类型。
181
183
</p >
182
184
183
185
<p >
184
- 当调用 <code >write()</code > 时,将会执行 <code >statementId</code > 属性中指定的映射语句。一般情况下,<code >write()</code > 应该在一个事务中进行调用。<br />
186
+ 当调用 <code >write()</code > 时,将会执行 <code >statementId</code >
187
+ 属性中指定的映射语句。一般情况下,<code >write()</code >
188
+ 应该在一个事务中进行调用。<br />
185
189
</p >
186
190
187
191
<p >下面是一个配置样例:</p >
@@ -201,18 +205,19 @@ public MyBatisBatchItemWriter<User> writer() {
201
205
}]]> </source >
202
206
203
207
204
- <p ><strong >Converting a item that read using ItemReader to an any parameter object: </strong ></p >
208
+ <p ><strong >将 ItemReader 读取的记录转换为任意的参数对象: </strong ></p >
205
209
206
210
<p >
207
- By default behavior, the <code >MyBatisBatchItemWriter</code > passes a item that read using <code >ItemReader</code >
208
- (or convert by <code >ItemProcessor</code >) to the MyBatis(<code >SqlSession#update()</code >) as the parameter object.
209
- If you want to customize a parameter object that passes to the MyBatis, you can realize to use the <code >itemToParameterConverter</code > option.
210
- For example using <code >itemToParameterConverter</code > option, you can passes any objects other than the item object to the MyBatis.
211
- Follows below a sample:
211
+ 默认情况下,<code >MyBatisBatchItemWriter</code > 会将 <code >ItemReader</code >
212
+ 读取的对象(或 <code >ItemProcessor</code > 转换过的对象) 以参数对象的形式传递给
213
+ MyBatis(<code >SqlSession#update()</code >)。
214
+ 如果你想自定义传递给 MyBatis 的参数对象,可以使用 <code >itemToParameterConverter</code > 选项。
215
+ 使用该选项后,可以传递任意对象给 MyBatis。
216
+ 举个例子:
212
217
</p >
213
218
214
219
<p >
215
- At first, you create a custom converter class (or factory method). The following sample uses a factory method.
220
+ 首先,创建一个自定义的转换器类(或工厂方法)。以下例子使用了工厂方法。
216
221
</p >
217
222
218
223
<source ><![CDATA[
@@ -227,7 +232,7 @@ public static <T> Converter<T, Map<String, Object>> createItemToParameterMapConv
227
232
}]]> </source >
228
233
229
234
<p >
230
- At next, you write a sql mapping.
235
+ 接下来,编写 SQL 映射。
231
236
</p >
232
237
233
238
<source ><![CDATA[
@@ -237,11 +242,11 @@ public static <T> Converter<T, Map<String, Object>> createItemToParameterMapConv
237
242
</select>]]> </source >
238
243
239
244
<p >
240
- At last, you configure the <code >MyBatisBatchItemWriter</code >.
245
+ 最后,配置 <code >MyBatisBatchItemWriter</code >。
241
246
</p >
242
247
243
248
<source ><![CDATA[
244
- // Sample for Java Config
249
+ // Java 配置样例
245
250
@Bean
246
251
public MyBatisBatchItemWriter<Person> writer() throws Exception {
247
252
return new MyBatisBatchItemWriterBuilder<Person>()
@@ -252,7 +257,7 @@ public MyBatisBatchItemWriter<Person> writer() throws Exception {
252
257
}]]> </source >
253
258
254
259
<source ><![CDATA[
255
- <!-- Sample for XML Config -->
260
+ <!-- XML 配置样例 -->
256
261
<bean id="writer" class="org.mybatis.spring.batch.MyBatisBatchItemWriter">
257
262
<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
258
263
<property name="statementId" value="org.mybatis.spring.sample.mapper.PersonMapper.createPerson"/>
0 commit comments