首页 > 其他分享 >结果集映射

结果集映射

时间:2023-02-13 13:55:55浏览次数:36  
标签:映射 结果 column pojo 嵌套 property id select

多对一

  • 按照查询嵌套处理:需要两个查询,被嵌套的<association>需要column以及select属性

  • 按照结果嵌套处理:不需要column以及select属性

对于数据库的字段和pojo里面的字段一致时,不需要在繁琐的配置,只需要配置不一样的字段即可

 <resultMap id="Orders" type="com.ahrtolia.entity.Order">
        <id property="id" column="oId"></id>
        <result property="count" column="ocount"></result>
        <association property="product" javaType="com.ahrtolia.entity.Product">
            <result property="name" column="name"></result>
            <result property="fileName" column="fileName"></result>
            <result property="price" column="price"></result>
        </association>
    </resultMap>
    <select id="getMyProductCar" resultMap="Orders">
        select o.id as oId,o.count as ocount,p.name as name,p.fileName as fileName,p.price as price
        from orders as o,product as p
        where o.userId= #{userId} and o.productId = p.id  and state = 0;
    </select>

<resultMap>

  • id的值对应resultMap的值
  • type为返回的类型

<result>和<id>都可以用

  • property(pojo类的字段)映射为column(数据库的列名)

<collection>

  • property
  • ofType表示集合里面的泛型类型

<association>用于处理对象

  • property属性为当前pojo类里面的引用对象的类型
  • column为property对应的字段(这里把对象看成普通列就好理解了)
  • javaType为引用对象对应的pojo类
  • select为当前resultMap对应的select查询的id

 一对多差别不大

标签:映射,结果,column,pojo,嵌套,property,id,select
From: https://www.cnblogs.com/happy12123/p/17116087.html

相关文章