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" class="PetitionLetter">
		<result property="id" 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" resultClass="ProcessFlow"
		parameterClass="int">
		select * from t_processflow where id = #id# 24.
	</select>
	<select id="selectReporter" resultClass="Reporter"
		parameterClass="int">
		select * from t_reporter where id = #id# 28.
	</select>
	<select id="selectLetterInformation" resultClass="LetterInformation"
		parameterClass="int">
		select * from t_letterinformation where id = #id# 32.
	</select>
	<select id="selectSupervision" resultClass="Supervision"
		parameterClass="int">
		select * from t_supervision where id = #id#
	</select>
	<select id="selectPetitonLetterById" parameterClass="int"
		resultMap="PetitionLetterResult">
		select * from t_petitionletter where id = #id#
	</select>
</sqlMap>


你可能感兴趣的:(ibatis,qq)