article
public class Article {
private Integer id;
private String title;
private String content;
// 表示当前文章代表的评论列表
private List<Comment> commentList;
@Override
public String toString() {
return "Article{" +
"id=" + id +
", title='" + title + '\'' +
", content='" + content + '\'' +
", commentList=" + commentList +
'}';
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public List<Comment> getCommentList() {
return commentList;
}
public void setCommentList(List<Comment> commentList) {
this.commentList = commentList;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
mapper
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.Ivan.mapper.ArticleMapper">
<!--一对多关联查询:查询所有的用户,同时还要查询出每个用户所关联的订单信息-->
<resultMap id="articleMap" type="com.Ivan.domain.Article">
<id property="id" column="id"></id>
<result property="title" column="title"></result>
<result property="content" column="content"></result>
<!--
collection : 一对多使用 collection 标签进行关联
-->
<collection property="commentList" ofType="com.Ivan.domain.Comment" fetchType="lazy">
<id property="id" column="cid"></id>
<result property="content" column="content"/>
<result property="author" column="author"/>
<result property="a_id" column="a_id" />
</collection>
</resultMap>
<select id="displayAllArticle" resultMap="articleMap">
SELECT a.*,c.id cid,c.content, c.author,c.a_id FROM t_comment c RIGHT JOIN t_article a ON c.a_id = a.id
</select>
</mapper>
部分 sqlmapConfig
<settings>
<!--开启全局延迟加载功能-->
<setting name="lazyLoadingEnabled" value="true"/>
<!--所有方法都会延迟加载-->
<setting name="lazyLoadTriggerMethods" value="toString()"/>
<!--
因为 cacheEnabled 的取值默认就为 true,所以这一步可以省略不配置。
为 true 代表开启二级缓存;为 false 代表不开启二级缓存。
-->
<setting name="cacheEnabled" value="false"/>
</settings>
结果中的 commentList 还是照常显示。。。是哪里出了问题?