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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值