在上述代码中,resultMap中应该如何做参数对应
时间: 2024-03-23 16:37:41 浏览: 43
对于以上SQL语句,可以使用MyBatis的ResultMap来映射查询结果,代码示例如下:
```xml
<resultMap id="saleOrderResultMap" type="SaleOrderDTO">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="state" column="state"/>
<result property="dateOrder" column="date_order"/>
<result property="partnerName" column="r.name"/>
<result property="validityDate" column="validity_date"/>
<result property="createDate" column="create_date"/>
<result property="confirmationDate" column="confirmation_date"/>
<result property="userId" column="user_id"/>
<result property="partnerId" column="partner_id"/>
<result property="partnerInvoiceId" column="partner_invoice_id"/>
<result property="partnerShippingId" column="partner_shipping_id"/>
<result property="pricelistId" column="pricelist_id"/>
<result property="invoiceStatus" column="invoice_status"/>
<result property="note" column="note"/>
<result property="amountUntaxed" column="amount_untaxed"/>
<result property="amountTax" column="amount_tax"/>
<result property="amountTotal" column="amount_total"/>
<result property="paymentTermId" column="payment_term_id"/>
<result property="teamId" column="team_id"/>
<result property="createUid" column="create_uid"/>
<result property="writeUid" column="write_uid"/>
<result property="writeDate" column="write_date"/>
<result property="warehouseId" column="warehouse_id"/>
<result property="procurementGroupId" column="procurement_group_id"/>
<result property="deliveryConditions" column="delivery_conditions"/>
<result property="instructionOrder" column="instruction_order"/>
<result property="contractNo" column="contract_no"/>
<result property="transportType" column="transport_type"/>
<result property="isProvideInvoice" column="is_provide_invoice"/>
<result property="isProvideFreight" column="is_provide_freight"/>
<result property="contractDate" column="contract_date"/>
<result property="deliveryConditionsId" column="delivery_conditions_id"/>
<result property="isTax" column="is_tax"/>
<result property="worldchampBankId" column="worldchamp_bank_id"/>
<result property="amountTotalDaxie" column="amount_total_daxie"/>
<result property="isInventory" column="is_inventory"/>
</resultMap>
```
在以上ResultMap中,每个`<result>`标签的`property`属性表示Java类中对应的属性名称,`column`属性表示查询结果集中的列名。
然后在Mapper中的SQL语句中使用`resultMap`属性来引用该ResultMap,例如:
```xml
<select id="selectSaleOrderAndPartner" resultMap="saleOrderResultMap">
SELECT s.id, s.name, s.state, date_order, r.name, validity_date, s.create_date, confirmation_date, user_id, partner_id, partner_invoice_id, partner_shipping_id, pricelist_id, invoice_status, note, amount_untaxed, amount_tax, amount_total, payment_term_id, team_id, s.create_uid, s.write_uid, s.write_date, warehouse_id, procurement_group_id, delivery_conditions, instruction_order, contract_no, transport_type, is_provide_invoice, is_provide_freight, contract_date, delivery_conditions_id, is_tax, worldchamp_bank_id, amount_total_daxie, is_inventory
FROM sale_order s
LEFT JOIN res_partner r ON s.partner_id = r.id
ORDER BY s.id DESC
</select>
```
这样就完成了查询结果的映射。
阅读全文