mybatis一对多中collection配置无效,求解释

i244782405 2013-03-28 11:31:17
在配置中我配置了一个subject 对应 多个student 配置如下

<?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="Subject.mapper">
<select id="selectSubject" parameterType="int" resultType="com.demo.bean.Subject" resultMap="subjectMap">
select * from _subject where _id=#{id};
</select>
<resultMap type="com.demo.bean.Subject" id="subjectMap">
<id property="id" column="_id"/>
<result property="subName" column="sub_name"/>
<collection property="students" column="_subject" javaType="java.util.ArrayList" ofType="com.demo.bean.Student" select="selectStudents"></collection>
</resultMap>

<select id="selectStudents" resultType="com.demo.bean.Student" parameterType="int">
select _id as id ,_name as name ,_sex as sex
</select>
</mapper>


但是在查询的时候 没有查询出students(数据库里面的数据是正确的) 好像是 <collection property="students" column="_subject" javaType="java.util.ArrayList" ofType="com.demo.bean.Student" select="selectStudents"></collection>这条配置无效一样,就算是我把配置中的select="selectStudents" 胡乱改成select="123" 也不会报错,下面我的sql只写了一半 也不会报错,为什么呢 ?
...全文
2762 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
unix__linux 2013-07-19
  • 打赏
  • 举报
回复
也遇到这个问题了,折腾了大半天,最后发现,是由于即使用了别名,又做了映射造成的。要么使用别名后,映射的时候要使用column要用别名才行,要么就只用映射或者别名
ttccv 2013-05-19
  • 打赏
  • 举报
回复
是不是少了resultMap
i244782405 2013-03-28
  • 打赏
  • 举报
回复
貌似不是这个原因,奇怪了 弄了2天还是没弄好,
  • 打赏
  • 举报
回复
可能是别名一致造成的,id改为别的试下。

81,114

社区成员

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

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