数据结构
实体类
1 |
|
第一层查询实现逻辑
1、外层service将code字段传入queryRepetitionReport方法,该方法查询的code作为参数(column="{code=code}")传给queryDetailList
2、mybatis循环调用queryDetailList
相关代码如下:
1 | AchievementRepetitionVo queryRepetitionReport(String code); |
1 | <resultMap id="QueryRepetitionReportMap" type="AchievementRepetitionVo"> |
第二层查询实现逻辑
queryDetailList接收上一层查询返回的code字段,每一次执行queryDetailList方法都会把查询出的code、contrast_code字段传给queryContractList方法
mybatis再循环调用queryContractList方法。
相关代码如下:
1 | List<RepetitionDetailVo> queryDetailList(String code); |
1 | <resultMap id="QueryRepetitionDetailMap" type="com.aspirecn.rewardinnovation.entity.vo.achievementrepetition.RepetitionDetailVo"> |
第三层查询实现逻辑
queryContractList接收上一层查询返回的code、contrastCode字段,
mybatis再循环调用queryContractList方法
相关代码如下:
1 | List<RepetitionContractVo> queryContractList(String code, String contrastCode); |
1 | <select id="queryContractList" resultType="RepetitionContractVo"> |
总结
其实就是Collection放到resultMap,下一层把上一层的查询结果作为条件传入。
参考链接
碰到问题
第二层或者第三层的映射文件加上parameterType="string"会报"nested exception is org.apache.ibatis.reflection.ReflectionException: There is no setter for property named ‘code’ in 'class java.lang.String"错误
1 | <select id="queryDetailList" parameterType="string" resultMap="QueryRepetitionDetailMap"> |
原因不明,懂的大佬麻烦告知,不胜感激!