更新时间 2018-5-19
第一次写博客,先记下自己遇到的坑.后面不断完善.
collection一对多查询
<resultMap id="resultTestMap" type="resultTest">
<id property="resulttestid" column="resulttestid"/>
<result property="knr" column="knr"/>
<collection property="ptbList" ofType="ptb" column="resulttestid" select="selectPtb"/>
</resultMap>
<resultMap id="ptbMap" type="ptb">
<result property="ptbno" column="ptbno"/>
<result property="resulttestid" column="resulttestid"/>
</resultMap>
<select id="selectPtb" parameterType="java.lang.Integer" resultMap="ptbMap">
SELECT
ptbno
FROM ptb
WHERE resulttestid = #{resulttestid}
</select>
<select id="selectResultDetail" resultMap="resultTestMap">
SELECT
vin,
resulttestid
FROM result_test
WHERE knr = '2727791'
AND resulttestid = '1'
</select>
之前ptbList一直无法获取到值,弄了挺长时间没弄好.网上查资料感觉写法也没什么问题.后来才发现 selectResultDetail这里面要查询出resulttestid,这样才能把值传过去. 总之mybatis用collection 一对多查询的时候一定要也把关联字段查出来. 不管这个字段 有没有用到.
本文记录了在使用MyBatis进行一对多查询时遇到的问题,详细描述了如何处理嵌套查询中子集数据无法获取的情况,初学者可参考解决类似疑惑。
2678

被折叠的 条评论
为什么被折叠?



