mybatis 記錄

towboat發表於2024-10-06

巢狀物件對映

<resultMap id="userResultMap" type="com.example.User">
    <id property="id" column="user_id"/>
    <result property="name" column="user_name"/>
    <result property="age" column="user_age"/>
    <association property="address" javaType="com.example.Address">
        <id property="id" column="address_id"/>
        <result property="city" column="address_city"/>
        <result property="street" column="address_street"/>
    </association>
</resultMap>

集合對映

<resultMap id="userResultMap" type="com.example.User">
    <id property="id" column="user_id"/>
    <result property="name" column="user_name"/>
    <result property="age" column="user_age"/>
    <collection property="addresses" ofType="com.example.Address">
        <id property="id" column="address_id"/>
        <result property="city" column="address_city"/>
        <result property="street" column="address_street"/>
    </collection>
</resultMap>

相關文章