Skip to content

Commit 53a6aa6

Browse files
authored
Merge pull request #781 from c19354837/master
Translate for java-api
2 parents c065fd6 + 95db930 commit 53a6aa6

File tree

1 file changed

+43
-42
lines changed

1 file changed

+43
-42
lines changed

src/site/zh/xdoc/java-api.xml

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ MyBatis 很大程度简化了你的代码而且保持简洁,很容易理解和
7171
/web
7272
/WEB-INF
7373
/web.xml</pre>
74-
<p>Remember, these are preferences, not requirements, but others will thank you for using a common directory structure.</p>
74+
<p>当然这是推荐的目录结构,并非强制要求,但是使用一个通用的目录结构将更利于大家沟通。</p>
7575
<p>这部分内容剩余的示例将假设你使用了这种目录结构。</p>
7676
</subsection>
7777

@@ -85,7 +85,8 @@ SqlSessionFactoryBuilder 创建的,它可以从 XML 配置,注解或手动配置
8585
SqlSessionFactory。
8686
</p>
8787
<p>
88-
<span class="label important">NOTE</span> When using MyBatis with a dependency injection framework like Spring or Guice, SqlSessions are created and injected by the DI framework so you don't need to use the SqlSessionFactoryBuilder or SqlSessionFactory and can go directly to the SqlSession section. Please refer to the MyBatis-Spring or MyBatis-Guice manuals for further info.
88+
<span class="label important">注意</span>
89+
当Mybatis与一些依赖注入框架(如Spring或者Guice)同时使用时,SqlSessions将被依赖注入框架所创建,所以你不需要使用SqlSessionFactoryBuilder或者SqlSessionFactory,可以直接看SqlSession这一节。请参考Mybatis-Spring或者Mybatis-Guice手册了解更多信息。
8990
</p>
9091
<h4>SqlSessionFactoryBuilder</h4>
9192
<p>
@@ -363,8 +364,8 @@ public interface ResultHandler<T> {
363364
尔返回值的 stop()方法来停止 MyBatis 加载更多的结果。
364365
</p>
365366

366-
<h5>Batch update statement Flush Method</h5>
367-
<p>There is method for flushing(executing) batch update statements that stored in a JDBC driver class at any timing. This method can be used when you use the <code>ExecutorType.BATCH</code> as <code>ExecutorType</code>.</p>
367+
<h5>批量立即更新方法(Flush Method)</h5>
368+
<p>有一个方法可以刷新(执行)存储在JDBC驱动类中的批量更新语句。当你将<code>ExecutorType.BATCH</code>作为<code>ExecutorType</code>使用时可以采用此方法。</p>
368369
<source><![CDATA[List<BatchResult> flushStatements()]]></source>
369370

370371

@@ -391,8 +392,7 @@ void rollback(boolean force)</source>
391392
MyBatis 会替你完成。然而,如果你需要更多对多提交和回滚都可能的 session 的细粒度控
392393
制,你可以使用回滚选择来使它成为可能。
393394
</p>
394-
<p><span class="label important">NOTE</span> MyBatis-Spring and MyBatis-Guice provide declarative transaction handling. So if you are using MyBatis with Spring or Guice please refer to their specific manuals.</p>
395-
395+
<p><span class="label important">注意</span>MyBatis-Spring和MyBatis-Guice提供了声明事务处理,所以如果你在使用Mybatis的同时使用了Spring或者Guice,那么请参考它们的手册以获取更多的内容。</p>
396396
<h5>清理 Session 级的缓存</h5>
397397
<source>void clearCache()</source>
398398
<p>
@@ -540,7 +540,7 @@ flushInterval,size 和 readWrite。
540540
</tr>
541541
<tr>
542542
<td><code>@ConstructorArgs</code></td>
543-
<td><code>Method</code></td>
543+
<td><code>方法</code></td>
544544
<td><code>&lt;constructor&gt;</code></td>
545545
<td>收集一组结果传递给一个劫夺对象的
546546
构造方法。属性:value,是形式参数
@@ -597,7 +597,7 @@ ResultMap 很相似,由下面的 Results
597597
结果映射的列表,
598598
包含了一个特别结果
599599
列如何被映射到属性或字段的详情。
600-
属 性:value, id。value 属性是 Result 注解的数组。 The id attribute is the name of the result mapping.
600+
属 性:value, id。value 属性是 Result 注解的数组。这个id的属性是结果映射的名称。
601601
</td>
602602
</tr>
603603
<tr>
@@ -632,19 +632,17 @@ select,已映射语句(也就是映射器方
632632
型的实例。注意:联合映射在注解 API
633633
中是不支持的。这是因为 Java 注解的
634634
限制,不允许循环引用。
635-
<code>fetchType</code>, which supersedes the global configuration parameter <code>lazyLoadingEnabled</code> for this mapping.
635+
<code>fetchType</code>会覆盖全局的配置参数<code>lazyLoadingEnabled</code>
636636
</td>
637637
</tr>
638638
<tr>
639639
<td><code>@Many</code></td>
640640
<td><code>方法</code></td>
641641
<td><code>&lt;collection&gt;</code></td>
642-
<td>A mapping to a collection property of a complex type. Attributes: <code>select</code>, which is the fully
643-
qualified name of a mapped statement (i.e. mapper method) that can load a collection of instances of the appropriate
644-
types,
645-
<code>fetchType</code>, which supersedes the global configuration parameter <code>lazyLoadingEnabled</code> for this mapping.
646-
<span class="label important">NOTE</span> You will notice that join mapping is not supported via the
647-
Annotations API. This is due to the limitation in Java Annotations that does not allow for circular references.</td>
642+
<td>
643+
映射到复杂类型的集合属性。属性:<code>select</code>,已映射语句(也就是映射器方法)的全限定名,
644+
它可以加载合适类型的实例的集合,<code>fetchType</code>会覆盖全局的配置参数<code>lazyLoadingEnabled</code>。
645+
<span class="label important">注意</span>联合映射在注解 API中是不支持的。这是因为 Java 注解的限制,不允许循环引用</td>
648646
</tr>
649647
<tr>
650648
<td><code>@MapKey</code></td>
@@ -771,43 +769,46 @@ MyBatis
771769
</tr>
772770
<tr>
773771
<td><code>@SelectKey</code></td>
774-
<td><code>Method</code></td>
772+
<td><code>方法</code></td>
775773
<td><code>&lt;selectKey&gt;</code></td>
776-
<td>This annotation duplicates the <code>&lt;selectKey&gt;</code> functionality for methods annotated with
777-
<code>@Insert</code>, <code>@InsertProvider</code>, <code>@Update</code> or <code>@UpdateProvider</code>. It is ignored for other methods. If you specify a
778-
<code>@SelectKey</code> annotation, then MyBatis will ignore any generated key properties set via the
779-
<code>@Options</code> annotation, or configuration properties.
780-
Attributes: statement an array of strings which is the SQL statement to execute, <code>keyProperty</code> which
781-
is the property of the parameter object that will be updated with the new value, before which must be either
782-
<code>true</code> or <code>false</code> to denote if the SQL statement should be executed before or after the insert,
783-
<code>resultType</code> which is the Java type of the <code>keyProperty</code>, and <code>statementType=PREPARED</code>.</td>
774+
<td>
775+
该注解复制了<code>&lt;selectKey&gt;</code>的功能,用在注解了<code>@Insert</code>, <code>@InsertProvider</code>, <code>@Update</code> or <code>@UpdateProvider</code>的方法上。在其他方法上将被忽略。如果你指定了一个<code>@SelectKey</code>注解,然后Mybatis将忽略任何生成的key属性通过设置<code>@Options</code>,或者配置属性。
776+
属性:
777+
<code>statement</code>是要执行的sql语句的字符串数组,
778+
<code>keyProperty</code>是需要更新为新值的参数对象属性,
779+
<code>before</code>可以是<code>true</code>或者<code>false</code>分别代表sql语句应该在执行insert之前或者之后,
780+
<code>resultType</code>是<code>keyProperty</code>的Java类型,
781+
<code>statementType</code>是语句的类型,取<code>Statement</code>, <code>PreparedStatement</code>和<code>CallableStatement</code>对应的<code>STATEMENT</code>, <code>PREPARED</code>或者<code>CALLABLE</code>其中一个,默认是<code>PREPARED</code>。
782+
</td>
784783
</tr>
785784
<tr>
786785
<td><code>@ResultMap</code></td>
787-
<td><code>Method</code></td>
786+
<td><code>方法</code></td>
788787
<td>N/A</td>
789-
<td>This annotation is used to provide the id of a <code>&lt;resultMap&gt;</code> element in an XML mapper to a
790-
<code>@Select</code> or <code>@SelectProvider</code> annotation. This allows annotated selects to reuse resultmaps
791-
that are defined in XML. This annotation will override any <code>@Results</code> or <code>@ConstructorArgs</code>
792-
annotation if both are specified on an annotated select.</td>
788+
<td>
789+
这个注解给<code>@Select</code>或者<code>@SelectProvider</code>提供在XML映射中的<code>&lt;resultMap&gt;</code>的id。
790+
这使得注解的select可以复用那些定义在XML中的ResultMap。
791+
如果同一select注解中还存在<code>@Results</code>或者<code>@ConstructorArgs</code>,那么这两个注解将被此注解覆盖。
793792
</tr>
794793
<tr>
795794
<td><code>@ResultType</code></td>
796795
<td><code>Method</code></td>
797796
<td>N/A</td>
798-
<td>This annotation is used when using a result handler. In that case, the return type is void
799-
so MyBatis must have a way to determine the type of object to construct for each row.
800-
If there is an XML result map, use the @ResultMap annotation. If the result type is
801-
specified in XML on the <code>&lt;select&gt;</code> element, then no other annotation is
802-
necessary. In other cases, use this annotation. For example, if a @Select annotated method
803-
will use a result handler, the return type must be void and this annotation (or @ResultMap)
804-
is required. This annotation is ignored unless the method return type is void.</td>
797+
<td>
798+
当使用结果处理器时启用此注解。这种情况下,返回类型为void,所以Mybatis必须有一种方式决定对象的类型,用于构造每行数据。
799+
如果有XML的结果映射,使用<code>@ResultMap</code>注解。
800+
如果结果类型在XML的<code>&lt;select&gt;</code>节点中指定了,就不需要其他的注解了。
801+
其他情况下则使用此注解。比如,如果@Select注解在一个方法上将使用结果处理器,返回类型必须是void并且这个注解(或者@ResultMap)是必须的。
802+
这个注解将被忽略除非返回类型是void。
803+
</td>
805804
</tr>
806805
<tr>
807806
<td><code>@Flush</code></td>
808-
<td><code>Method</code></td>
807+
<td><code>方法</code></td>
809808
<td>N/A</td>
810-
<td>If this annotation is used, it can be called the <code>SqlSession#flushStatements()</code> via method defined at a Mapper interface.(MyBatis 3.3 or above)</td>
809+
<td>
810+
如果这个注解使用了,它将调用定义在Mapper接口中的<code>SqlSession#flushStatements()</code>方法。(Mybatis 3.3或者以上)
811+
</td>
811812
</tr>
812813
</tbody>
813814
</table>
@@ -823,11 +824,11 @@ MyBatis
823824
@SelectKey(statement="call identity()", keyProperty="nameId", before=<strong>false</strong>, resultType=<strong>int.class</strong>)
824825
<strong>int</strong> insertTable2(Name name);</source>
825826

826-
<p>This example shows using the <code>@Flush</code> annotation to call the <code>SqlSession#flushStatements()</code>:</p>
827+
<p>这个例子展示了如何使用<code>@Flush</code>注解去调用<code>SqlSession#flushStatements()</code>:</p>
827828
<source><![CDATA[@Flush
828829
List<BatchResult> flush();]]></source>
829830

830-
<p>These examples show how to name a ResultMap by specifying id attribute of @Results annotation.</p>
831+
<p>这些例子展示了如何通过指定@Result的id属性来命名结果集:</p>
831832
<source>@Results(id = "userResult", value = {
832833
@Result(property = "id", column = "uid", id = <strong>true</strong>),
833834
@Result(property = "firstName", column = "first_name"),
@@ -844,7 +845,7 @@ User getUserById(Integer id);
844845
@Select("select * from company where id = #{id}")
845846
Company getCompanyById(Integer id);</source>
846847

847-
<p>This example shows solo parameter using the Sql Provider annotation:</p>
848+
<p>这个例子展示了单一参数使用@SqlProvider:</p>
848849
<source><![CDATA[@SelectProvider(type = UserSqlBuilder.class, method = "buildGetUsersByName")
849850
List<User> getUsersByName(String name);
850851
@@ -861,7 +862,7 @@ class UserSqlBuilder {
861862
}
862863
}]]></source>
863864

864-
<p>This example shows multiple parameters using the Sql Provider annotation:</p>
865+
<p>这个列子展示了多参数使用@SqlProvider:</p>
865866
<source><![CDATA[@SelectProvider(type = UserSqlBuilder.class, method = "buildGetUsersByName")
866867
List<User> getUsersByName(
867868
@Param("name") String name, @Param("orderByColumn") String orderByColumn);

0 commit comments

Comments
 (0)