Mybatis_resultMap 逃离我推掉我的手 2023-06-25 12:30 27阅读 0赞 * resultMap主要用于查询一对多的关系条件下 <select id="selectByPoid" parameterType="long" resultMap="pomainResultMap"> select p1.*, p2.num poitemnum, p3.* from pomain p1,poitem p2 ,product p3 where p2.POID = p1.poid and p3.ProductCode = p2.ProductCode and p1.POID = #{poid} </select> <!-- resultMap 手动映射查询结果的列和java中的对象的属性 type - 对应java中对象的数据类型 --> <resultMap type="com.test.model.Pomain" id="pomainResultMap"> <!-- id 映射主键 column 查询结果的列名或者别名 property java对象中的set方法后的属性名 --> <!-- id 列相同时,不管result是否相同都会合并 全部定义成id或者全部定义成result 只有所有的列都相同时才会合并 --> <id column="poid" property="poId"/> <result column="venderCode" property="venderCode"/> <result column="account" property="account"/> <result column="createTime" property="createTime"/> <result column="tipFee" property="tipFee"/> <result column="productTotal" property="productTotal"/> <result column="poTotal" property="poTotal"/> <!-- 映射集合属性 包括list、数组、set ofType 设置集合中存放的对象的数据类型 --> <collection property="poitems" ofType="com.test.model.Poitem"> <id column="poId" property="poId"/> <id column="productCode" property="productCode"/> <result column="unitPrice" property="unitPrice"/> <result column="poitemnum" property="num"/> <result column="unitName" property="unitName"/> <!-- 映射对象属性 --> <association property="product" javaType="com.test.model.Product"> <id column="productCode" property="productCode"/> <result column="categoryId" property="categoryId"/> <result column="name" property="name"/> </association> </collection> </resultMap>
还没有评论,来说两句吧...