Mybatis配置文件中collection标签的定义问题

tmq77 2017-02-16 10:43:13
请问collection中的column到底指的什么

<resultMap id="clazzResultMap" type="org.fkit.domain.Clazz">
<id property="id" column="id" />
<result property="code" column="code"/>
<!-- 班级的学生属性,因为一个班级有多个学生,所以该属性是一个集合 -->
<collection property="students" javaType="ArrayList"
column="id" ofType="org.fkit.domain.Student"
select="selectStudentWithId"/>
</resultMap>


<!-- 映射学生对象的resultMap -->
<resultMap id="studentResultMap" type="org.fkit.domain.Student">
<id property="id" column="id" />
<result property="name" column="name"/>
<result property="sex" column="sex"/>
<result property="age" column="age"/>
<!-- 关联映射 -->
<association property="clazz" column="clazz_id"
javaType="org.fkit.domain.Clazz"
select="selectClazzWithId"/>
</resultMap>




<!-- 根据班级id查询班级 -->
<select id="selectClazzWithId" resultType="org.fkit.domain.Clazz">
SELECT * FROM TB_CLAZZ where id = #{id}
</select>

<!-- 查询所有学生信息 -->
<select id="selectStudent" resultMap="studentResultMap">
SELECT * FROM TB_STUDENT
</select>

<!-- 根据班级id查询学生 -->
<select id="selectStudentWithId" resultType="org.fkit.domain.Student">
SELECT * FROM TB_STUDENT where clazz_id = #{id}
</select>

<!-- 查询所有班级信息 -->
<select id="selectClazz" resultMap="clazzResultMap">
SELECT * FROM TB_CLAZZ
</select>



这里面的column指的是Clazz对应表的id列还是Student对应表的id列
column="clazz_id"这个又指的是哪个表的哪个参数。。。
...全文
737 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tmq77 2017-02-24
  • 打赏
  • 举报
回复
谢谢各位解惑!
GrayHJX 2017-02-16
  • 打赏
  • 举报
回复
谢邀。result里面的column是数据库表对应字段,property是实体类对应字段。collection是对于你的数据库表取那么个集合出来,用于聚合查询,这个博客可以帮助你理解collection的使用http://blog.csdn.net/minpann/article/details/51217106
菜 头 2017-02-16
  • 打赏
  • 举报
回复
你所返回的字段名
妙笔生花tys 2017-02-16
  • 打赏
  • 举报
回复
<collection property="students" javaType="ArrayList" <span style="color: #FF0000;"> column="id"</span> ofType="org.fkit.domain.Student" select="selectStudentWithId"/> ofType关联到了学生表的查询,所以你根据班级ID查询,会返回学生表的学生ID集合 <association property="clazz" <span style="color: #FF0000;">column="clazz_id"</span> javaType="org.fkit.domain.Clazz" select="selectClazzWithId"/> 这句会返回班级表的班级ID

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧