1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
2
<!--
3
3
4
- Copyright 2009-2021 the original author or authors.
4
+ Copyright 2009-2022 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.
@@ -388,8 +388,8 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
388
388
<td >复杂类型的单个属性映射。属性:
389
389
<code >select</code >,指定可加载合适类型实例的映射语句(也就是映射器方法)全限定名;
390
390
<code >fetchType</code >,指定在该映射中覆盖全局配置参数 <code >lazyLoadingEnabled</code >;
391
- <code >resultMap</code >(available since 3.5.5) , which is the fully qualified name of a result map that map to a single container object from select result;
392
- <code >columnPrefix</code >(available since 3.5.5), which is column prefix for grouping select columns at nested result map.
391
+ <code >resultMap</code >( 3.5.5以上可用) , which is the fully qualified name of a result map that map to a single container object from select result;
392
+ <code >columnPrefix</code >( 3.5.5以上可用),结果集的完全限定名,该结果映射到查询结果中的集合对象;
393
393
<span class =" label important" >提示</span > 注解 API 不支持联合映射。这是由于 Java 注解不允许产生循环引用。</td >
394
394
</tr >
395
395
<tr >
@@ -399,8 +399,8 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
399
399
<td >复杂类型的集合属性映射。属性:
400
400
<code >select</code >,指定可加载合适类型实例集合的映射语句(也就是映射器方法)全限定名;
401
401
<code >fetchType</code >,指定在该映射中覆盖全局配置参数 <code >lazyLoadingEnabled</code >
402
- <code >resultMap</code >(available since 3.5.5), which is the fully qualified name of a result map that map to collection object from select result ;
403
- <code >columnPrefix</code >(available since 3.5.5), which is column prefix for grouping select columns at nested result map.
402
+ <code >resultMap</code >( 3.5.5以上可用),结果集的完全限定名,该结果映射到查询结果中的集合对象 ;
403
+ <code >columnPrefix</code >( 3.5.5以上可用),在嵌套的结果集中对所查询的列进行分组的列前缀。
404
404
<span class =" label important" >提示</span > 注解 API 不支持联合映射。这是由于 Java 注解不允许产生循环引用。</td >
405
405
</tr >
406
406
<tr >
@@ -414,10 +414,9 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
414
414
<td ><code >方法</code ></td >
415
415
<td >映射语句的属性</td >
416
416
<td >该注解允许你指定大部分开关和配置选项,它们通常在映射语句上作为属性出现。与在注解上提供大量的属性相比,<code >Options</code > 注解提供了一致、清晰的方式来指定选项。属性:<code >useCache=true</code >、<code >flushCache=FlushCachePolicy.DEFAULT</code >、<code >resultSetType=DEFAULT</code >、<code >statementType=PREPARED</code >、<code >fetchSize=-1</code >、<code >timeout=-1</code >、<code >useGeneratedKeys=false</code >、<code >keyProperty=""</code >、<code >keyColumn=""</code >、<code >resultSets=""</code >, <code >databaseId=""</code >。注意,Java 注解无法指定 <code >null</code > 值。因此,一旦你使用了 <code >Options</code > 注解,你的语句就会被上述属性的默认值所影响。要注意避免默认值带来的非预期行为。
417
- The <code >databaseId</code >(Available since 3.5.5), in case there is a configured <code >DatabaseIdProvider</code >,
418
- the MyBatis use the <code >Options</code > with no <code >databaseId</code > attribute or with a <code >databaseId</code >
419
- that matches the current one. If found with and without the <code >databaseId</code > the latter will be discarded.<br /><br />
420
-
417
+ <code >databaseId</code >(3.5.5以上可用), 如果有一个配置好的 <code >DatabaseIdProvider</code >,
418
+ MyBatis 会加载不带 <code >databaseId</code > 属性和带有匹配当前数据库 <code >databaseId</code > 属性的所有语句。如果同时存在带 <code >databaseId</code > 和不带 <code >databaseId</code > 属性的相同语句,则后者会被舍弃。<br /><br />
419
+
421
420
注意:<code >keyColumn</code > 属性只在某些数据库中有效(如 Oracle、PostgreSQL 等)。要了解更多关于 <code >keyColumn</code > 和 <code >keyProperty</code > 可选值信息,请查看“insert, update 和 delete”一节。</td >
422
421
</tr >
423
422
<tr >
@@ -440,9 +439,8 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
440
439
</td >
441
440
<td >
442
441
每个注解分别代表将会被执行的 SQL 语句。它们用字符串数组(或单个字符串)作为参数。如果传递的是字符串数组,字符串数组会被连接成单个完整的字符串,每个字符串之间加入一个空格。这有效地避免了用 Java 代码构建 SQL 语句时产生的“丢失空格”问题。当然,你也可以提前手动连接好字符串。属性:<code >value</code >,指定用来组成单个 SQL 语句的字符串数组。
443
- The <code >databaseId</code >(Available since 3.5.5), in case there is a configured <code >DatabaseIdProvider</code >,
444
- the MyBatis use a statement with no <code >databaseId</code > attribute or with a <code >databaseId</code >
445
- that matches the current one. If found with and without the <code >databaseId</code > the latter will be discarded.
442
+ <code >databaseId</code >(3.5.5以上可用), 如果有一个配置好的 <code >DatabaseIdProvider</code >,
443
+ MyBatis 会加载不带 <code >databaseId</code > 属性和带有匹配当前数据库 <code >databaseId</code > 属性的所有语句。如果同时存在带 <code >databaseId</code > 和不带 <code >databaseId</code > 属性的相同语句,则后者会被舍弃。
446
444
</td >
447
445
</tr >
448
446
<tr >
@@ -470,9 +468,8 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
470
468
(The <code >type</code > attribute is alias for <code >value</code >, you must be specify either one.
471
469
But both attributes can be omit when specify the <code >defaultSqlProviderType</code > as global configuration)。
472
470
<code >method</code > 用于指定该类的方法名(从版本 3.5.1 开始,可以省略 <code >method</code > 属性,MyBatis 将会使用 <code >ProviderMethodResolver</code > 接口解析方法的具体实现。如果解析失败,MyBatis 将会使用名为 <code >provideSql</code > 的降级实现)。<span class =" label important" >提示</span > 接下来的“SQL 语句构建器”一章将会讨论该话题,以帮助你以更清晰、更便于阅读的方式构建动态 SQL。
473
- The <code >databaseId</code >(Available since 3.5.5), in case there is a configured <code >DatabaseIdProvider</code >,
474
- the MyBatis will use a provider method with no <code >databaseId</code > attribute or with a <code >databaseId</code >
475
- that matches the current one. If found with and without the <code >databaseId</code > the latter will be discarded.
471
+ <code >databaseId</code >(3.5.5以上可用), 如果有一个配置好的 <code >DatabaseIdProvider</code >,
472
+ MyBatis 会加载不带 <code >databaseId</code > 属性和带有匹配当前数据库 <code >databaseId</code > 属性的所有语句。如果同时存在带 <code >databaseId</code > 和不带 <code >databaseId</code > 属性的相同语句,则后者会被舍弃。
476
473
</td >
477
474
</tr >
478
475
<tr >
@@ -487,9 +484,8 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
487
484
<td ><code >< selectKey> </code ></td >
488
485
<td >
489
486
这个注解的功能与 <code><selectKey></code> 标签完全一致。该注解只能在 <code>@Insert</code> 或 <code>@InsertProvider</code> 或 <code>@Update</code> 或 <code>@UpdateProvider</code> 标注的方法上使用,否则将会被忽略。如果标注了 <code>@SelectKey</code> 注解,MyBatis 将会忽略掉由 <code>@Options</code> 注解所设置的生成主键或设置(configuration)属性。属性:<code>statement</code> 以字符串数组形式指定将会被执行的 SQL 语句,<code>keyProperty</code> 指定作为参数传入的对象对应属性的名称,该属性将会更新成新的值,<code>before</code> 可以指定为 <code>true</code> 或 <code>false</code> 以指明 SQL 语句应被在插入语句的之前还是之后执行。<code>resultType</code> 则指定 <code>keyProperty</code> 的 Java 类型。<code>statementType</code> 则用于选择语句类型,可以选择 <code>STATEMENT</code>、<code>PREPARED</code> 或 <code>CALLABLE</code> 之一,它们分别对应于 <code>Statement</code>、<code>PreparedStatement</code> 和 <code>CallableStatement</code>。默认值是 <code>PREPARED</code>。
490
- The <code >databaseId</code >(Available since 3.5.5), in case there is a configured <code >DatabaseIdProvider</code >,
491
- the MyBatis will use a statement with no <code >databaseId</code > attribute or with a <code >databaseId</code >
492
- that matches the current one. If found with and without the <code >databaseId</code > the latter will be discarded.
487
+ <code >databaseId</code >(3.5.5以上可用), 如果有一个配置好的 <code >DatabaseIdProvider</code >,
488
+ MyBatis 会加载不带 <code >databaseId</code > 属性和带有匹配当前数据库 <code >databaseId</code > 属性的所有语句。如果同时存在带 <code >databaseId</code > 和不带 <code >databaseId</code > 属性的相同语句,则后者会被舍弃。
493
489
</td >
494
490
</tr >
495
491
<tr >
@@ -586,26 +582,26 @@ class UserSqlBuilder {
586
582
}
587
583
}]]> </source >
588
584
589
- <p >This example shows usage that share an sql provider class to all mapper methods using global configuration(Available since 3.5.6) :</p >
585
+ <p >这是一个在全局配置下让所有映射方法在同一个 sql provider 类里面的例子( 3.5.6 后可用) :</p >
590
586
<source ><![CDATA[
591
587
Configuration configuration = new Configuration();
592
- configuration.setDefaultSqlProviderType(TemplateFilePathProvider.class); // Specify an sql provider class for sharing on all mapper methods
588
+ configuration.setDefaultSqlProviderType(TemplateFilePathProvider.class); // 让所有映射方法在同一个 sql provider 类里面
593
589
// ...]]> </source >
594
590
<source ><![CDATA[
595
- // Can omit the type/value attribute on sql provider annotation
596
- // If omit it, the MyBatis apply the class that specified on defaultSqlProviderType.
591
+ // 在 sql provider 注解上可以省略 type/value 属性
592
+ // 如果省略, MyBatis 将使用 defaultSqlProviderType 所指定的类
597
593
public interface UserMapper {
598
594
599
- @SelectProvider // Same with @SelectProvider(TemplateFilePathProvider.class)
595
+ @SelectProvider // 等价于 @SelectProvider(TemplateFilePathProvider.class)
600
596
User findUser(int id);
601
597
602
- @InsertProvider // Same with @InsertProvider(TemplateFilePathProvider.class)
598
+ @InsertProvider // 等价于 @InsertProvider(TemplateFilePathProvider.class)
603
599
void createUser(User user);
604
600
605
- @UpdateProvider // Same with @UpdateProvider(TemplateFilePathProvider.class)
601
+ @UpdateProvider // 等价于 @UpdateProvider(TemplateFilePathProvider.class)
606
602
void updateUser(User user);
607
603
608
- @DeleteProvider // Same with @DeleteProvider(TemplateFilePathProvider.class)
604
+ @DeleteProvider // 等价于 @DeleteProvider(TemplateFilePathProvider.class)
609
605
void deleteUser(int id);
610
606
}]]> </source >
611
607
@@ -629,11 +625,11 @@ class UserSqlProvider implements ProviderMethodResolver {
629
625
}
630
626
}]]> </source >
631
627
632
- < p >This example shows usage the < code >databaseId</code > attribute on the statement annotation(Available since 3.5.5): </p >
628
+ < p >这个例子展现了如何在声明注解时使用< code >databaseId</code >属性( 3.5.5后可用): </p >
633
629
<source ><![CDATA[
634
- @Select(value = "SELECT SYS_GUID() FROM dual", databaseId = "oracle") // Use this statement if DatabaseIdProvider provide "oracle"
635
- @Select(value = "SELECT uuid_generate_v4()", databaseId = "postgres") // Use this statement if DatabaseIdProvider provide "postgres"
636
- @Select("SELECT RANDOM_UUID()") // Use this statement if the DatabaseIdProvider not configured or not matches databaseId
630
+ @Select(value = "SELECT SYS_GUID() FROM dual", databaseId = "oracle") // 如果 DatabaseIdProvider 提供的是 "oracle",使用这条语句
631
+ @Select(value = "SELECT uuid_generate_v4()", databaseId = "postgres") // 如果 DatabaseIdProvider 提供的是 "postgres",使用这条语句
632
+ @Select("SELECT RANDOM_UUID()") // 如果 DatabaseIdProvider 没有配置或者没有对应的 databaseId, 使用这条语句
637
633
String generateId();
638
634
]]> </source >
639
635
0 commit comments