问题描述
在进行联合查询的时候得到只有一条记录,而实际结果应该是多条记录的;当我值查询一张表的字段时得到的结果就是多条的,这是为什么呢?我的映射写错了?还是SQL有问题?部分代码如下:publicclassAssessTeach{privateLongid;privateStringstaffid;privateStringcontent;//其他属性以及getter()andsetter()方法就不写了}
publicclassAssessTeachComp{privateStringyear="";privateAssessTeachentity=null;//其他属性以及getter()andsetter()方法就不写了}
相关配置文件如下:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEmapperPUBLIC"-//ibatis.apache.org//DTDMapper3.0//EN""http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"><!--不使用namespace的话sql搜索定位会比较方便--><mappernamespace="AssessTeach"><resultMapid="RM.AssessTeachComp"type="com.zf.hrm.assess.model.AssessTeachComp"><resultproperty="year"column="YEAR"/><resultproperty="editable"column="EDITABLE"/><associationproperty="entity"javaType="com.zf.hrm.assess.model.AssessTeach"resultMap="RM.AssessTeach"></association></resultMap><resultMapid="RM.AssessTeach"type="com.zf.hrm.assess.model.AssessTeach"><idproperty="id"column="ID"/><resultproperty="staffid"column="STAFFID"/><resultproperty="starttime"column="STARTTIME"/><resultproperty="endtime"column="ENDTIME"/><resultproperty="curriculum"column="CURRICULUM"/><resultproperty="content"column="CONTENT"/><resultproperty="kind"column="KIND"/><resultproperty="student"column="STUDENT"/><resultproperty="studentcount"column="STUDENTCOUNT"/><resultproperty="sumhour"column="SUMHOUR"/><resultproperty="assess"column="ASSESS"/><resultproperty="remark"column="REMARK"/></resultMap><sqlid="AssessTeach.compColumns"><!--此处定义字段时删除YEAR和EDITABLE就能够查询到多条--><![CDATA[YEAR,EDITABLE,B.ID,B.STAFFID,B.STARTTIME,B.ENDTIME,B.CURRICULUM,B.CONTENT,B.KIND,B.STUDENT,B.STUDENTCOUNT,B.SUMHOUR,B.ASSESS,B.REMARK]]></sql><selectid="AssessTeach.list"resultMap="RM.AssessTeachComp">SELECT<includerefid="AssessTeach.compColumns"/><![CDATA[FROMASSESS_TEACH_COMP,ASSESS_TEACHBWHERETEACH_ID=B.IDANDYEAR=#{year}ANDB.STAFFID=#{entity.staffid}]]></select></mapper>
解决方案
解决方案二:
这么没人帮忙啊