@@ -788,11 +788,11 @@ resultMap 元素有很多子元素和一个值得讨论的结构。
788
788
</ul >
789
789
790
790
<table >
791
- <caption >ResultMap Attributes </caption >
791
+ <caption >ResultMap属性 </caption >
792
792
<thead >
793
793
<tr >
794
- <th >Attribute </th >
795
- <th >Description </th >
794
+ <th >属性 </th >
795
+ <th >描述 </th >
796
796
</tr >
797
797
</thead >
798
798
<tbody >
@@ -1185,8 +1185,8 @@ prop1 和 prop2 以参数对象形式来设置给目标嵌套查询语句。
1185
1185
<tr >
1186
1186
<td ><code >fetchType</code ></td >
1187
1187
<td >
1188
- Optional. Valid values are <code >lazy</code > and <code >eager</code >. If present, it supersedes
1189
- the global configuration parameter <code >lazyLoadingEnabled</code > for this mapping.
1188
+ 可选的。有效值为 <code >lazy</code >和 <code >eager</code >。
1189
+ 如果使用了,它将取代全局配置参数 <code >lazyLoadingEnabled</code >。
1190
1190
</td >
1191
1191
</tr >
1192
1192
</tbody >
@@ -1269,25 +1269,25 @@ resultMap
1269
1269
<tr >
1270
1270
<td ><code >columnPrefix</code ></td >
1271
1271
<td >
1272
- When joining multiple tables, you would have to use column alias to avoid duplicated
1273
- column names in the ResultSet. Specifying columnPrefix allows you to map such columns
1274
- to an external resultMap. Please see the example explained later in this section.
1272
+ 当连接多表时,你将不得不使用列别名来避免ResultSet中的重复列名。指定columnPrefix允许你映射列名到一个外部的结果集中。
1273
+ 请看后面的例子。
1275
1274
</td >
1276
1275
</tr >
1277
1276
<tr >
1278
1277
<td ><code >notNullColumn</code ></td >
1279
1278
<td >
1280
- By default a child object is created only if at least one of the columns mapped to the child's properties
1281
- is non null. With this attribute you can change this behaviour by specifiying which columns must have a value
1282
- so MyBatis will create a child object only if any of those columns is not null. Multiple column names can be
1283
- specified using a comma as a separator. Default value: unset.
1279
+ 默认情况下,子对象仅在至少一个列映射到其属性非空时才创建。
1280
+ 通过对这个属性指定非空的列将改变默认行为,这样做之后Mybatis将仅在这些列非空时才创建一个子对象。
1281
+ 可以指定多个列名,使用逗号分隔。默认值:未设置(unset)。
1284
1282
</td >
1285
1283
</tr >
1286
1284
<tr >
1287
1285
<td ><code >autoMapping</code ></td >
1288
- <td >If present, MyBatis will enable or disable auto-mapping when mapping the result to this property.
1289
- This attribute overrides the global autoMappingBehavior.
1290
- Note that it has no effect on an external resultMap, so it is pointless to use it with <code >select</code > or <code >resultMap</code > attribute. Default value: unset.
1286
+ <td >
1287
+ 如果使用了,当映射结果到当前属性时,Mybatis将启用或者禁用自动映射。
1288
+ 该属性覆盖全局的自动映射行为。
1289
+ 注意它对外部结果集无影响,所以在<code >select</code > or <code >resultMap</code >属性中这个是毫无意义的。
1290
+ 默认值:未设置(unset)。
1291
1291
</td >
1292
1292
</tr >
1293
1293
</tbody >
@@ -1363,8 +1363,8 @@ resultMap
1363
1363
</resultMap>]]> </source >
1364
1364
1365
1365
<p >
1366
- What if the blog has a co-author?
1367
- The select statement would look like:
1366
+ 如果blog有一个co-author怎么办?
1367
+ select语句将看起来这个样子:
1368
1368
</p >
1369
1369
1370
1370
<source ><![CDATA[ <select id="selectBlog" resultMap="blogResult">
@@ -1388,7 +1388,7 @@ resultMap
1388
1388
</select>]]> </source >
1389
1389
1390
1390
<p >
1391
- Recall that the resultMap for Author is defined as follows.
1391
+ 再次调用Author的resultMap将定义如下:
1392
1392
</p >
1393
1393
1394
1394
<source ><![CDATA[ <resultMap id="authorResult" type="Author">
@@ -1400,8 +1400,8 @@ resultMap
1400
1400
</resultMap>]]> </source >
1401
1401
1402
1402
<p >
1403
- Because the column names in the results differ from the columns defined in the resultMap,
1404
- you need to specify <code >columnPrefix</code > to reuse the resultMap for mapping co-author results.
1403
+ 因为结果中的列名与resultMap中的列名不同。
1404
+ 你需要指定 <code >columnPrefix</code >去重用映射co-author结果的resultMap。
1405
1405
</p >
1406
1406
1407
1407
<source ><![CDATA[ <resultMap id="blogResult" type="Blog">
@@ -1700,25 +1700,23 @@ MyBatis 会从结果集中得到每条记录,
1700
1700
</resultMap>]]> </source >
1701
1701
1702
1702
<p >
1703
- There are three auto-mapping levels:
1703
+ 有三种自动映射等级:
1704
1704
</p >
1705
1705
1706
1706
<ul >
1707
1707
<li >
1708
- <code >NONE</code > - disables auto-mapping. Only manually mapped properties will be set.
1708
+ <code >NONE</code > - 禁用自动映射。仅设置手动映射属性。
1709
1709
</li >
1710
1710
<li >
1711
- <code >PARTIAL</code > - will auto-map results except those that have nested result mappings defined inside (joins).
1711
+ <code >PARTIAL</code > - 将自动映射结果除了那些有内部定义内嵌结果映射的 (joins).
1712
1712
</li >
1713
1713
<li >
1714
- <code >FULL</code > - auto-maps everything.
1714
+ <code >FULL</code > - 自动映射所有。
1715
1715
</li >
1716
1716
</ul >
1717
1717
1718
1718
<p >
1719
- The default value is <code >PARTIAL</code >, and it is so for a reason. When <code >FULL</code > is used auto-mapping will
1720
- be performed when processing join results and joins retrieve data of several different entities in the same row
1721
- hence this may result in undesired mappings. To understand the risk have a look at the following sample:
1719
+ 默认值是<code >PARTIAL</code >,这是有原因的。当使用<code >FULL</code >时,自动映射会在处理join结果时执行,并且join取得若干相同行的不同实体数据,因此这可能导致非预期的映射。下面的例子将展示这种风险:
1722
1720
</p >
1723
1721
1724
1722
<source ><![CDATA[ <select id="selectBlog" resultMap="blogResult">
@@ -1739,14 +1737,12 @@ MyBatis 会从结果集中得到每条记录,
1739
1737
</resultMap>]]> </source >
1740
1738
1741
1739
<p >
1742
- With this result map both <i >Blog</i > and <i >Author</i > will be auto-mapped. But note that <i >Author</i > has an <i >id</i >
1743
- property and there is a column named <i >id</i > in the ResultSet so Author's id will be filled with Blog's id, and that is not
1744
- what you were expecting. So use the <code >FULL</code > option with caution.
1740
+ 在结果中<i >Blog</i >和<i >Author</i >均将自动映射。但是注意<i >Author</i >有一个<i >id</i >属性,在ResultSet中有一个列名为<i >id</i >,
1741
+ 所以Author的id将被填充为Blog的id,这不是你所期待的。所以需要谨慎使用<code >FULL</code >。
1745
1742
</p >
1746
1743
1747
1744
<p >
1748
- Regardless of the auto-mapping level configured you can enable or disable the automapping for an specific ResultMap
1749
- by adding the attribute <code >autoMapping</code > to it:
1745
+ 通过添加<code >autoMapping</code >属性可以忽略自动映射等级配置,你可以启用或者禁用自动映射指定的ResultMap。
1750
1746
</p >
1751
1747
1752
1748
<source ><![CDATA[ <resultMap id="userResultMap" type="User" autoMapping="false">
0 commit comments