zhuyumu 发表于 2016-11-24 02:11:38

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>
页: [1]
查看完整版本: mybatis知识