mybatis設置一對多映射

mybatis設置一對多映射

 

1.映射文件mybatis

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    
<mapper namespace="com.kerwin.mybatis.pojo.Person">
    <resultMap type="com.kerwin.mybatis.pojo.Person" id="personreSultMap">
        <id column="p_id" property="id"/>
        <result column="name" property="name"/>
        <collection property="orderList" ofType="com.kerwin.mybatis.pojo.Orders" column="pid">
            <id column="o_id" property="id"/>
            <result column="price" property="price"/>
        </collection>
        
    </resultMap>
    
    <select id="selectPersonFetchOrder" parameterType="int" resultMap="personreSultMap" >
        select p.*,o.* from person p,orders o where o.pid=p.p_id and p.p_id=#{id}
    </select>
</mapper>app

 

Person實體中添加orderList的集合。spa

相關文章
相關標籤/搜索