mybatis知识

一、封装ibatis中数据,设置外键值为集合
1.封装mybatis中数据,设置外键值为集合list,通过配置<constructor>
<resultMap id="recordsResult" type="com.cmbstc.bass.system.po.MessageRecords" >
<constructor>
<idArg column="RECORDSID" javaType="int"/>
</constructor>
</resultMap>

2.需要添加构造方法

public MessageRecords(){

}
public MessageRecords(Integer recordsId){
this.recordsId = recordsId;
}

二、在mybatis中配置集合类型,使用关键字“collection”
1.在mybatis中配置集合类型,使用关键字“collection”
<resultMap id="messageResult" type="com.cmbstc.bass.system.po.Message">
<result property="messageId" column="MESSAGEID" />
<result property="messageContent" column="MESSAGECONTENT" />
<result property="status" column="STATUS" />
<result property="messageDate" column="MESSAGEDATE" />
<result property="msgType" column="MSGTYPE" />
<result property="messageTitle" column="MSGTITLE" />
<association property="creator" column="USERID" resultMap="usersResult"/>
<collection property="records" resultMap="recordsResult"/>
</resultMap>

2.association用来配置MessageRecords中的实体
<resultMap id="recordsResult" type="com.cmbstc.bass.system.po.MessageRecords" >
<constructor>
<idArg column="RECORDSID" javaType="int"/>
</constructor>
<!-- <result property="recordsId" column="RECORDSID" /> -->
<result property="status" column="MSGSTATUS" />
<association property="receiver" column="receiverID"
javaType="com.cmbstc.bass.system.po.User">
<result property="userId" column="receiverID" />
<result property="userName" column="receiverName" />
</association>
</resultMap>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值