权威的文档当然要看官方的文档说明
上面有一些面试题还有mybatis的各种问题
mybatis源码系列
场景:行业查询,一级行业,二级行业
1、POJO
@Getter
@Setter
public class XXXEntity implements Serializable {
private Integer id;
private String name;
private Integer parentId;
private Integer level;
// 节点是否展开,true展开,false折叠
private boolean open;
private List<XXXEntity> second;
}
2、mapper
一对多的ResultMap
<resultMap id="SecondResultMap" type="com.xxx.xxx.entity.XXXEntit ">
<id column="pkid" jdbcType="INTEGER" property="id"/>
<result column="trade_tag" jdbcType="VARCHAR" property="name"/>
<result column="parent_id" jdbcType="INTEGER" property="parentId"/>
<result column="level" jdbcType="INTEGER" property="level"/>
<collection property="seconds" ofType="com.xxx.xxx.entity.XXXEntity"
column="pkid" select="getSecondList">
</collection>
</resultMap>
<select id="getSecondList" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"></include>
from trade_info
where level = 2 AND parent_id = #{pkid}
</select>
还有另一种写法,是将id,result在collection里面再重复一遍,个人不喜欢这种方式,觉得上面这种方式清晰明了