feat:更新埃学习文档

This commit is contained in:
2026-06-01 19:58:05 +08:00
parent 2777ef8676
commit a825ccdadb
3 changed files with 56 additions and 10 deletions

View File

@@ -262,10 +262,47 @@ public interface UserMapper {
</resultMap>
```
&emsp;&emsp;其中`<collection>`也可以使用嵌套查询:
&emsp;&emsp;对应的数据结构为:
```java
public class Blog {
private Integer id;
private String title;
private Author author; // 一对一
private List<Post> posts; // 一对多
}
public class Author {
private Integer id;
private String username;
private String password;
private String email;
private String bio;
private String favouriteSection;
}
public class Post {
private Integer id;
private String subject;
private Author author; // 一对一
private List<Comment> comments; // 一对多
private List<Tag> tags; // 一对多
}
public class Comment {
private Integer id;
}
public class Tag {
private Integer id;
}
```
&emsp;&emsp;其中`<collection>`也可以使用嵌套查询,例如`<collection property="posts" ofType="Post" select="queryPost"/>`
```xml
<collection property="posts" ofType="Post" select="queryPost"/>
<select id="queryPost" resultMap="postResultMap">
</select>
<resultMap id="postResultMap" type="Post">
<id property="id" column="post_id"/>
@@ -281,11 +318,6 @@ public interface UserMapper {
<case value="1" resultType="DraftPost"/>
</discriminator>
</resultMap>
<select id="queryPost" resultMap="postResultMap">
</select>
```
&emsp;&emsp;如果需要传递参数,可以在`<collection>`添加`column`属性:
@@ -304,7 +336,12 @@ public interface UserMapper {
+ 映射语句文件中的所有 select 语句的结果将会被缓存。
+ 映射语句文件中的所有 insert、update 和 delete 语句会刷新缓存。
+ 一级缓存和二级缓存区别在于一级缓存只针对一次SqlSession二级缓存针对全局范围。
+ 一级缓存和二级缓存区别在于一级缓存只针对一次SqlSession二级缓存针对全局范围。
::: tip
一级缓存作用于service里面的同一个方法一个方法就是一个SqlSession多次查询时直接返回缓存数据如果是同一个service里面的不同方法就是多个SqlSession一级缓存会失效。
二级缓存作用于同一个mapper即使是不同的service的不同方法只要是同一个mapper都可以使用二级缓存。
:::
## 4.6 动态SQL
+ if :是/否