mybatis一对多关系配置
resultMap返回类型配置
<resultMap id="baseResultMap" type="cn.com.api.res.CityOperatorsManageInfoWrapper">
<result column="city_code" property="city_code" jdbcType="INTEGER" />
<result column="count" property="count" jdbcType="INTEGER" />
<result column="currentCount" property="currentCount" jdbcType="INTEGER" />
<collection property="areaLists" column="city_code"
fetchType="eager"
ofType="cn.com.api.entity.CityOperatorsManageInfo"
select="getAreasByCityCode">
</collection>
</resultMap>
属性含义
1. property 对应javaBean(pojo)中的属性值
2. column 对应数据库中的字段
3. jdbcType 对应数据库中字段类型
collection
- 可用于一对一
- collection元素 对应javaBean中的集合类型,如List
- property对应javabean中集合的名称
- column 一对多关联关系
- fetchType 懒加载声明,若mybatis配置文件中的lazyLoadingEnabled属性设置为true,则一对多加载时必须生命fetchType属性
- ofType 一对多查询时,多的一方返回的类型
- select 一对多查询的查询语句,需要在xml映射文件中声明,id为select的值
mybatis一对一查询
association
resultMap配置
<association property="teacher" javaType="com.lcb.user.Teacher">
<id property="id" column="t_id"/>
<result property="name" column="t_name"/>
</association>