feat:更新埃学习文档
This commit is contained in:
@@ -262,10 +262,47 @@ public interface UserMapper {
|
||||
</resultMap>
|
||||
```
|
||||
|
||||
  其中`<collection>`也可以使用嵌套查询:
|
||||
  对应的数据结构为:
|
||||
```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;
|
||||
}
|
||||
```
|
||||
|
||||
  其中`<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>
|
||||
|
||||
```
|
||||
|
||||
  如果需要传递参数,可以在`<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 :是/否
|
||||
|
||||
Reference in New Issue
Block a user