ibatis的含有外键的OR映射
对于有外键的主表映射,在查询返回结果时要使用resultmap进行映射,并在propety里使用select属性进行子查询。
/** * @author jelly qq:136179492 */public class PetitionLetter {private int id;private String identifier;private Reporter reporter; // 外键,数据库里是int类型private LetterInformation letterInformation; // 外键,数据库里是int类型private Supervision supervision; // 外键,数据库里是int类型private ProcessFlow processFlow; // 外键,数据库里是int类型}/** * @author jelly qq:136179492 */public class PetitionLetter {private int id;private String identifier;private Reporter reporter; // 外键,数据库里是int类型private LetterInformation letterInformation; // 外键,数据库里是int类型private Supervision supervision; // 外键,数据库里是int类型private ProcessFlow processFlow; // 外键,数据库里是int类型}
<sqlMap namespace="PetitionLetter"><typeAlias alias="PetitionLetter"type="com.cs.jfb.input.model.PetitionLetter" /><typeAlias alias="ProcessFlow"type="com.cs.jfb.process.model.ProcessFlow" /><typeAlias alias="Reporter" type="com.cs.jfb.input.model.Reporter" /><typeAlias alias="LetterInformation"type="com.cs.jfb.input.model.LetterInformation" /><typeAlias alias="Supervision"type="com.cs.jfb.supervision.model.Supervision" /><resultMap id="PetitionLetterResult" column="id" /><result property="identifier" column="identifier" /><result property="reporter" column="reporter"select="selectReporter" /><result property="letterInformation" column="letterInformation"select="selectLetterInformation" /><result property="supervision" column="supervision"select="selectSupervision" /><result property="processFlow" column="processFlow"select="selectProcessFlow" /></resultMap><!-- Select with no parameters using the result map for Account class. --><select id="selectAllPetitionLetter"resultMap="PetitionLetterResult">select * from t_petitionletter 20.</select><select id="selectProcessFlow" resultresultresultresultparameterClass="int"resultMap="PetitionLetterResult">select * from t_petitionletter where id = #id#</select></sqlMap>